i need scipt that load after x number of times

Discussion in 'HTML & Website Design' started by anil verma, May 1, 2013.

  1. #1
    hello expert
    i need script that load after x number of times
    let say if page load 1 to 10 time ..i want it load on 10 time and agian 1 to 9 it will not used or place any other code
    i want to use this lag in my body tag of page
    <script src="example.js"></script>


    if any help it will nice ..watting see reply
     
    anil verma, May 1, 2013 IP
  2. cadsii

    cadsii Well-Known Member

    Messages:
    220
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #2
    setup a cookie counter
    when the user logs in update the cookie

    this is in PHP but can be done in jQuery


    <?php

    if (isset($_COOKIE['pageload'])) {
    if (intval($_COOKIE['pageload']) > 9) {
    // do stuff here on 10th load
    setcookie('pageload', 1);
    } else {
    setcookie('pageload', intval($_COOKIE['pageload']) + 1);
    }
    } else {
    setcookie('pageload', 1);
    }

    ?>
     
    cadsii, May 2, 2013 IP
  3. anil verma

    anil verma Member

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #3
    hey thanks your Reply cadsii

    i am not expert in html and php codes i am just creating this code of my own site .
    that code u have give me ..i am not able to understand it .
    Let me explain to you again please do reply Full codes so i able to understand it
    Basically i need

    To Run 2 scripts it will be in jquery Let put name A and B
    Like
    <script src="jqueryscriptA.js"></script>

    and
    <script src="jqueryscriptB.js"></script>

    it will but in Under body tag

    <Body></Body>



    When web page load for 10 times in user PC( it can use cookie method as above cadsii is telling ) or page load counter will best

    in between 1 to 9 load script A should work at 10 page load script B work at that time ..and agian when 1 to 9 ..

    i think it will clear to All web masters

    Please reply with All codes because i am not expert but i am trying to learn it
     
    anil verma, May 2, 2013 IP
  4. cadsii

    cadsii Well-Known Member

    Messages:
    220
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #4
    dont forget to show appreciation for my answers


    <?php

    if (isset($_COOKIE['pageload'])) {
    if (intval($_COOKIE['pageload']) > 9) {
    // do stuff here on 10th load
    echo '<script src="jqueryscriptA.js"></script>';
    setcookie('pageload', 1);
    } else {
    echo '<script src="jqueryscriptB.js"></script>';
    setcookie('pageload', intval($_COOKIE['pageload']) + 1);
    }
    } else {
    setcookie('pageload', 1);
    }

    ?>


    if you have php access just dump it into any php file in between the body, but it can be in the header as well
     
    cadsii, May 2, 2013 IP
  5. anil verma

    anil verma Member

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #5
    Hello i have try your code but i am getting in my site
    Warning: Cannot modify header information - headers already sent by (output started at
     
    at end it say on line 11 
    Code (markup):
    i have try to put in site in head
    like
    <script src="file.php"></script>
     
    anil verma, May 5, 2013 IP
  6. cadsii

    cadsii Well-Known Member

    Messages:
    220
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #6
    script is for java not php, make a .php file and call it from the browser
     
    cadsii, May 6, 2013 IP