Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Using header function send visitor to one page and then to another

    I have a code
    PHP Code:
    <?php
    header
    ('Location: http://localhost/comments/comments.html');
    sleep(20);
    header('Location: http://www.google.com');
    in this case page on localhost is not loading. Opera just prints "sending request to localhost…" messages but I can not see comments.html and at the end google.com is loading.
    When I remove call to a sleep function I am redirecting right to google.com. Even, without pause.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    The browser is not going to load one webpage (thus discarding your headers) and then load another page. No browser will work like that. If they did it would be a major security flaw and millions of people would have their browsers hijacked on a daily basis by anyone who has no hacking skill at all.

    The browser will always try to execute the last header instruction in the reply headers. Granted if it gets an earlier one it will try to execute it if practical but when it recieves another it will automatically cancel the first one and execute the latter one.

    To put it bluntly your code will never work. If you want to do something like that you will need to use an iframe and javascript.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Tags for this Thread

    Posting Permissions

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