#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0

    Php transfer code


    hi , i want one code for one of my pages , its php!
    i want when someone came to my page after 2 sec it'll transfer to another page and after 7 sec came back to the first page and stop ! i mean only one time work each day for one user !

    and i found one code from one of my friend , but this code it works but when i added it to my index.php its not work like that! its work but when it came back after 7 sec to the first page it'll not stop , it'll continue again !! please tell me what should i do?

    this is the code for the first page:
    PHP Code:
    <?php
    @session_start();
    @
    ob_start();
    $url='re2.php';
    if(!
    $_SESSION["zegersot"])
    {
    $_SESSION["zegersot"]=true;
    echo <<<HTML
    <meta http-equiv="refresh" content="2; url= $url">
    HTML;
    }
    ?>
    and this is for second page:
    PHP Code:
    <meta http-equiv="refresh" content="7; url= re.php"
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,571
    Rep Power
    595
    PHP cannot control the client side very effectively. You are better off doing this with Javascript.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by gw1500se
    PHP cannot control the client side very effectively. You are better off doing this with Javascript.
    ok can u tell me how can i do that with javascript ? who can make it? really i want it
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,571
    Rep Power
    595
    I've request this be transferred to the Javascript forum for you.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by gw1500se
    I've request this be transferred to the Javascript forum for you.
    wow thank u so much , and how can i fallow the Javascript forum ?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,571
    Rep Power
    595
    After it is moved, go here.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,247
    Rep Power
    9400

    Moved from PHP


    The window.setTimeout function can execute code after X milliseconds.
    Code:
    window.setTimeout(function() {
        document.location = "new URL";
    }, 2000); // 2 seconds
    A meta refresh like your code has can also work.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    The window.setTimeout function can execute code after X milliseconds.
    Code:
    window.setTimeout(function() {
        document.location = "new URL";
    }, 2000); // 2 seconds
    A meta refresh like your code has can also work.
    how can i use this to my index.php ? i mean what is the totally code i have to put in my index.php?
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    We're not going to simply do your work for you. Javascript goes in <script> tags inside the <head> tags.

    He also mentioned that what you already have works.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by ManiacDan
    We're not going to simply do your work for you. Javascript goes in <script> tags inside the <head> tags.

    He also mentioned that what you already have works.
    sorry i couldn't understand because i'm beginner can u tell me what code i have to use to my index.htm ? after to sec go to other page and after 7 sec came back but i should be stop here ..!
  20. #11
  21. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,247
    Rep Power
    9400
    Then use some sort of logic to decide that, on the second time through, the redirection stuff (whatever it may be) does not run. Maybe it doesn't get outputted, maybe it does but doesn't execute. You probably need to track the fact that the redirection happened: a cookie or a value in the PHP session can do that.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    Then use some sort of logic to decide that, on the second time through, the redirection stuff (whatever it may be) does not run. Maybe it doesn't get outputted, maybe it does but doesn't execute. You probably need to track the fact that the redirection happened: a cookie or a value in the PHP session can do that.
    HOW ABT THIS? IS IT GOOD??
    PAGE1:
    Code:
    <!DOCTYPE html>
    <html>
    <body style="background-color: pink;">
    <h1>THIS IS PAGE 1</h1>
    
    <script type="text/javascript">
    (
      function( )
      {
          if ( location.search.indexOf("STOP") < 0 )
          {
              setTimeout( function() { location.href = "page2.html"; }, 2000 );
          } else {
              document.body.style.backgroundColor = "lime";
          }
      }
    )();
    </script>
    </body>
    </html>
    PAGE2:
    Code:
    <!DOCTYPE html>
    <html>
    <body style="background-color: lightblue;">
    <h1>PAGE TWO PAGE 2 PAGE TWO</h1>
    
    <script type="text/javascript">
    (
      function( )
      {
          setTimeout( function() { location.href = "page1.html?STOP"; }, 7000 );
      }
    )();
    </script>
    </body>
    </html>

IMN logo majestic logo threadwatch logo seochat tools logo