SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Sunderland
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie: probably a daftly simple question about reloading web pages

    I am an intermediately-skilled web designer working on a database driven site for my company, and learning php and mysql at the same time. I have what I think is probably a basic question, but I'm stuck with it.

    I have created a simple login system that allows users to type in a password (which allows them to see dicounted prices on product pages), and I've put the login form at the top of each page so that viewers can login from anywhere in the site. What I want to do is, after typing in a password, the viewer is taken to a 'login successful/unsuccessful' page and then get taken back to the page they were at. I can take them to the success/fail page but how do I then take them back to the page they logged in on, after a 3-second delay? I need to be able to program this in PHP.

    Any help is gratefully appreciated. I'm sure this is just some simple referral code thing, but I'm still learning HTML and CSS as well as PHP and MySQL.

    Thanks,

    Matt

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <meta http-equiv="Refresh" content="3;url=/index.php">
    Note that you should also have a link on the 'successful/unsuccessful' page, because not every browser supports this redirect method. Also, client-side redirects can cause accessibility problems, especially for people who don't read quickly enough. Some people may not be able to read your 'successful/unsuccessful' message in 3 seconds.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Sunderland
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This takes me back to the index page, not the previously viewed page. I've been searching through the forums and picked up on code like 'parse_url($HTTP_REFERRER)' - can I use that to somehow replace your reference to index.php? Is there some simple PHP code I can use?

    Thanks for your quick response, by the way!

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want it to return to different pages, you'll need to write the URL in your PHP script. The best way would be to supply the URL in a hidden field in the form, and pick it up in the login script.

    The next best way might be to use the HTTP 'Referer' (note the spelling error) header, but that's not completely reliable since it can be turned off in some browsers, and also by proxies and firewalls. You could do something like this:
    PHP Code:
    echo '<meta http-equiv="Refresh" content="3;url='
      
    $_SERVER['HTTP_REFERER']
      . 
    '">'
    (Again, note the incorrect spelling of referrer.)
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Sunderland
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YES!!! Brilliant!

    Thanks ever so much!

  6. #6
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also set a real HTTP header instead of using the META element.
    PHP Code:
    <?php
    header
    ("Refresh: 3; $_SERVER['HTTP_REFERER']");
    ?>
    Simon Pieters


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
  •