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
    May 2003
    Location
    UK
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Header('Location.... not always working

    Please help!

    I am struggling with getting this to work,

    header("location: " . $url);

    If I put in at the top of a page like this

    <?php header("location: " . $url); ?>


    it works every time. But if i put it on a page with some require_once() statements above it - it works about 50% of the time. It will work 5 times in a row then every other time then maybe 10 times it won't work. It's completely random!

    When I say that it doesn't work, what I mean is that it redirects as requested - but the new page doesn't show. I just get a blank screen. If I press refresh on the browser then it shows the page ok.
    When I check the source for the blank screen it looks like this...


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
    <BODY></BODY></HTML>


    There is no whitespace in my code - this would prevent the redirect from happening at all.
    The coding of the redirect is fine - as it works 50% of the time.

    Can anyone help - maybe even a workaround that could cause the new page to refresh would help - but as I cant get the new page to show then the refresh code will also not work.
    Is it possible to force the NEXT page to refresh??

    Probably not as I am not really sure what I mean by that at all.

    All help appreciated.
    They only tell you its a stupid question when they don't know the answer!

  • #2
    New Coder
    Join Date
    May 2003
    Location
    UK
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Solved it!

    Well by brute force (trying everything), I have solved it.

    When I included the session id in the querystring it suddenly worked. It just happens that the session files were one of the require_once() included files.

    I think that the MySql server was not to happy with being hit for 2 session writes in the same split second.
    Now I include the session id in the redirect url and the second page doesn't have to create a new one it just verifys (reads) the id provided.

    Permanent connections to the db would be a solution - but they bring their own nightmares.
    They only tell you its a stupid question when they don't know the answer!


  •  

    Posting Permissions

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