New Coder Posted February 3, 2010 Share Posted February 3, 2010 Hello all, I have been looking into using $_SERVER['HTTP_REFERER'] to populate the href of a back link. I thought this would be a good idea as I have a login page that can be accessed from pretty much every page on my site. I wanted the user to be able to go back to the page they last viewed before they logged in. eg. The user has browsed to the gallery page as a guest. They then decide they wish to upload an image. Uploading images can only be done by a logged on user. So they click the login link at the top of the page. They login, a message is displayed saying welcome and they are presented with a back link or button. So I was thinking: <form action="<?php echo $_SERVER['HTTP_REFERER']; ?>"><input type="submit" value="Back" /></form> or <a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">Back</a> Is there a better way? Many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/190798-_serverhttp_referer-is-there-a-better-solution/ Share on other sites More sharing options...
Zyx Posted February 3, 2010 Share Posted February 3, 2010 The only other possible idea is to pass the previous URL via sessions, cookies or URL. HTTP_REFERER is sometimes reconfigured in the browser to pass different address than it is supposed to, but actually you should not be worried about that. If someone has such stupid ideas as using the protocol fields for different purposes, he should not be surprised that something does not work for him. Quote Link to comment https://forums.phpfreaks.com/topic/190798-_serverhttp_referer-is-there-a-better-solution/#findComment-1006115 Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2010 Share Posted February 3, 2010 is there a better solution?? Yes, think of the log in as a 'box' or a code block that you include on any page that needs it (such as the way this forum handles the log in.) If the visitor is not logged in, the log in form is displayed in a specific region on the page. The log in form submits back to the current page. The code that processes the log in form is part of the code block that you included on the page. If you are logged in, the username and a log out link/menu is displayed instead. Quote Link to comment https://forums.phpfreaks.com/topic/190798-_serverhttp_referer-is-there-a-better-solution/#findComment-1006123 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.