marmite Posted April 18, 2007 Share Posted April 18, 2007 Hey, My http_referer is coming up blank on my localhost, and from what I've read today it's unreliable, so I'd like to remove it from the site. What I'm trying to achieve is a redirect from my login page, depending on which page the user came from. I.e. there are several processes requiring logins, and I want to return them to where they came from once they logged in. Does anyone know of another way of doing this? Been stuck all day ??? Thanks Emma Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/ Share on other sites More sharing options...
soycharliente Posted April 18, 2007 Share Posted April 18, 2007 <?php if($whatever) { $page = $_POST["where_they_came_from"]; echo " <script type=\"text/javascript\"> <!-- window.location = \"$page\"; --> </script> "; } ?> I would do something like that. I always use JS to redirect. Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232332 Share on other sites More sharing options...
marmite Posted April 18, 2007 Author Share Posted April 18, 2007 Thanks for this. I'm not familiar with JS, can I just check: 1) Re: $_POST["where_they_came_from"] How do I do this bit? Do I have to set a variable on each page and carry it to each new page? 2) is the below as good as using window.location? if ($_POST['referer'] == "http://localhost/login.php") { header("Location: http://localhost/myaccount.php"); exit(); 3) Also, could you also tell me the significance of "/" versus "\" in javascript? I keep seeing it in my site's code and I'd love to know! Thanks a lot Emma Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232345 Share on other sites More sharing options...
soycharliente Posted April 18, 2007 Share Posted April 18, 2007 1. Yes. You could grab the URL and just pass it to each new page with a $_SESSION or $_POST variable. 2. Yes. It's the same. I've had problems in the past with using header() and having no clue why it wasn't working. I started using the JS redirect and have never looked back ;] 3. I don't understand what you mean with the slashes. You'll have to give me some example code to explain. They could have many different uses (escape characters, regular text, url paths, etc). Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232349 Share on other sites More sharing options...
per1os Posted April 18, 2007 Share Posted April 18, 2007 The JS Redirect is slower than using the header. As long as you do the page right there is no problem re-directing using the header location. As for passing data from your pages I would session instead of POST, unless you are having them submit it via a form. As for the third I only ever see the "/" used in the definition of the script. As seen in Charlie's code he uses the \ to escape the quotes. Anyhow I would highly suggest using Header over the JSRedirect for speed and efficiency. That and you never know if your users have JS disabled. Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232350 Share on other sites More sharing options...
marmite Posted April 18, 2007 Author Share Posted April 18, 2007 Thank you both SO much. The $_SESSION tip has cleared up another problem I was unwittingly having with $_POST. I've not got it working entirely but at least it's keeping variables between screens Ta! Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232365 Share on other sites More sharing options...
marmite Posted April 18, 2007 Author Share Posted April 18, 2007 however this doesn't do anything (it stays on the same page, index.php). Hmmm. It's definitely seeing the line of code as I have an echo wrapped around it. Any ideas? header("Location: http://localhost/index.php"); Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232383 Share on other sites More sharing options...
marmite Posted April 18, 2007 Author Share Posted April 18, 2007 I mean it stays on the same page, login.php. d'oh! Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232387 Share on other sites More sharing options...
per1os Posted April 18, 2007 Share Posted April 18, 2007 header("Location: http://localhost/index.php"); die(); Try adding a die statement, see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232431 Share on other sites More sharing options...
marmite Posted April 18, 2007 Author Share Posted April 18, 2007 nope, no joy (but thanks) Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232538 Share on other sites More sharing options...
marmite Posted April 18, 2007 Author Share Posted April 18, 2007 Solved - I had some echo's before the exit statement (not allowed, apparently). Now works. Thanks for help. Quote Link to comment https://forums.phpfreaks.com/topic/47592-alternative-to-http_referer/#findComment-232557 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.