Ask: Refresh sometimes working, sometimes not

Discussion in 'PHP' started by junandya, Jan 17, 2008.

  1. #1
    Hi,

    I use this script to redirect the page to the previous page after user login.
    echo "<META HTTP-EQUIV=\"refresh\" content=\"1; URL=javascript:history.back(-1)\">";
    PHP:
    But, sometimes it is not working properly, i mean the page is stop and show white blank page, and not back to the previous page.

    I want to ask:
    1. why it is not working constantly?
    2. should i give a redirect button to counter this problem at the mentioned page?

    Thanks for your help
     
    junandya, Jan 17, 2008 IP
  2. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not use php to send it back instead of doing a meta refresh...

    header("Location: " . $_SERVER['HTTP_REFERER']);
    PHP:
     
    Gawk, Jan 17, 2008 IP
  3. junandya

    junandya Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Thanks for your reply,

    why i did it like that, because i have to show some text to the user as notification if their login has succeed, about 1 or 2 second before it redirected to the previous page. but i did what you mention above for some other pages
     
    junandya, Jan 17, 2008 IP
  4. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Be careful with the code. Some browsers don't send a referer, and it's easily fakeable, allowing you to inject code (i.e. a newline then a new header). I would hardcode your login URL, far safer and guarantees 100% compatibility.
     
    jayshah, Jan 17, 2008 IP
  5. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Good advice.
     
    Gawk, Jan 17, 2008 IP
  6. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If the refresh is unreliable then a 'click here to continue' link or button would be a good option. You could also try using javascript do the redirect.
     
    Gawk, Jan 17, 2008 IP
  7. mlkshake

    mlkshake Peon

    Messages:
    73
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Why not change the javascript:history.back(-1) to
    $_SERVER['HTTP_REFERER']
    PHP:
     
    mlkshake, Jan 17, 2008 IP
  8. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #8
    Are we back here again?

    Applies more to HTML injection in this case ;)
     
    jayshah, Jan 17, 2008 IP
  9. junandya

    junandya Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #9
    @jayshah: do you mean that <META HTTP-EQUIV=\"refresh\" this script is dangerous? please explain it further, i'm not too smart in programming.

    Gents, can some one give me a best code to solve my problem, i mean just like this forum, after your login succeed, you will redirected to the previous page...

    Thanks
     
    junandya, Jan 17, 2008 IP
  10. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    you mentioned you are having problem sometimes not always...

    i guess this is the problem;

    history.back() won't work if you visited previous page with a form post method.. So, i guess may be sometimes you visits your previous page with a form post method thatz why history.back never works to go back to that page.

    hope it helps..
     
    webexpert, Jan 17, 2008 IP
  11. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #11
    What if it took them two tries to log in?

    Your login page should record the URL that the user originally wanted to go to, and explicitly send them there when the login has succeeded.
     
    SmallPotatoes, Jan 17, 2008 IP
  12. junandya

    junandya Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #12
    @SmallPotatoes: that's what i want to do before, but the only thing that i know is use
    URL=javascript:history.back(-1)
    PHP:
    could you show me how to do that? it's hard to do for me because there are so many GET variables that shown on URL, this is for example :
    localhost/test123/nextPage.php?ctnt=News&loader=Main&levCat=srcNews&src=News&hal=1&ctry=103
    PHP:
    That's why i use that javascript...

    I hope someone here could solve my problem here...

    Thanks
     
    junandya, Jan 17, 2008 IP
  13. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #13
    In theory you will find the original request, including all the GET args, in $_SERVER['REQUEST_URI'] - you can store that in a session variable while you are processing the login and then redirect the user to it once they're in.
     
    SmallPotatoes, Jan 18, 2008 IP