SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP - Like Javascript

    Using PHP, how do I replace the current page with another website, without navigating to a different page, resulting in the browser's Forward and Back buttons becoming enabled.

    See Javascript below that achieves this, can PHP do the same?

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <title></title>
    <script>
    function leavePage() {
      location.replace('http://www.google.com/')
    }
    var leaveTimeoutID=""; // the global var to hold the timeout id
    var leaveTime = 5; // seconds 
    function initLeave() {
       clearTimeout(leaveTimeoutID); // stop the function
       leaveTimeoutID=setTimeout('leavePage()',leaveTime*1000); // leave in leaveTime seconds
       // comment or delete next line when you are happy
       now = new Date(); window.status="leaving in 5 seconds: " + new Date(now.setSeconds(now.getSeconds()+5)) 
    }
    </script>  
      </head>
      <body onLoad="initLeave()" onMouseMove="initLeave()">
    
      </body>
    </html>

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    header('Location: http://www.google.com/');
    exit;
    Make sure you do this before sending any HTML out to the browser or you will get an error.

  3. #3
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stymiee View Post
    Code:
    header('Location: http://www.google.com/');
    exit;
    Make sure you do this before sending any HTML out to the browser or you will get an error.
    How do I navigate to a page, after adding information to a database?

  4. #4
    SitePoint Zealot glowdot's Avatar
    Join Date
    Jun 2007
    Location
    Santa Monica, CA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salchester View Post
    How do I navigate to a page, after adding information to a database?
    Do all your database stuff before sending the redirect header.

    As long as you don't output anything, this will work.

    Code:
    mysql_query("UPDATE table SET field='new value'")
    
    ...
    ...
    
    header('location: http://domain.com/newurl/');
    exit;
    Advertise on Glowfoto
    banners as low as $25/month, text ads $10/month
    Share 10 million impressions per month!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •