aebstract Posted February 15, 2008 Share Posted February 15, 2008 Is there a way I can check and see if someone came from a specific page? Not to see what page they came from but just do like an if: if(user came from page 1) { do something } else { do something else } Really only need to check it from one page, might add 2-3 more but I can just run an elseif or something if I need to. Can anyone point me in the direct of checking if they came from a specific page or not? Let me know if my question isn't clear enough. Quote Link to comment https://forums.phpfreaks.com/topic/91284-how-could-i-do-something-like-this/ Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 if($_SERVER['HTTP_REFERRER'] == "/script.php"){ // you can continue }else { // failed } Quote Link to comment https://forums.phpfreaks.com/topic/91284-how-could-i-do-something-like-this/#findComment-467823 Share on other sites More sharing options...
aebstract Posted February 15, 2008 Author Share Posted February 15, 2008 Okay I just came up with one flaw with this, is there a way to make it check if the user clicked a specific href link? Quote Link to comment https://forums.phpfreaks.com/topic/91284-how-could-i-do-something-like-this/#findComment-467850 Share on other sites More sharing options...
Psycho Posted February 15, 2008 Share Posted February 15, 2008 Sure, put a variable on the URL of the link and check it on the receiving page: LINK: <a href="somepage.php?switch=true">Click Me</a> PROCESSING PAGE: <?php if ($_GET['switch']=='true') { //Link was clicked } else { //Link was NOT clicked } ?> This is not a 100% guarantee, since the user can type the url and the varialbe as well, but would be OK for most usage. Quote Link to comment https://forums.phpfreaks.com/topic/91284-how-could-i-do-something-like-this/#findComment-467858 Share on other sites More sharing options...
aebstract Posted February 15, 2008 Author Share Posted February 15, 2008 Yeah I could have done that, but I'd rather it all be hidden from the user. Quote Link to comment https://forums.phpfreaks.com/topic/91284-how-could-i-do-something-like-this/#findComment-467881 Share on other sites More sharing options...
Psycho Posted February 15, 2008 Share Posted February 15, 2008 It would be very helpful if you were specific in your questions. mgallforever, gave you a solution for your first question as posed, but then you changed the request. I then gave you a solution but you now say it does not meet your needs because of a requiremetn that you did not state. You state that you want to know "whick link" was clicked on that page. Does that mean there are multiple links on that page that go to the same palce? It would be helpful if you explained what you are trying to accomplish. One "possible" solution would be to not have those links go directly to the intended page. instead have them go to separate intermediary pages: Instead of: <a href="nextpage.php">Link 1</a> <a href="nextpage.php">Link 2</a> Use this: <a href="nextpage1.php">Link 1</a> <a href="nextpage1.php">Link 2</a> And then for those pages (nextpage1.php & nextpage2.php): include(nextpage.php) You could then add code on those pages to 1) verify they are coming from the appropriate page and 2) know which link they clicked. Quote Link to comment https://forums.phpfreaks.com/topic/91284-how-could-i-do-something-like-this/#findComment-467928 Share on other sites More sharing options...
aebstract Posted February 18, 2008 Author Share Posted February 18, 2008 eh, I'm sorry for not being detailed enough.. wasn't intended, thought I was being so. Basically there is a link on a page, it goes to the login page. If the user logs in after clicking that link, it will take them back to that page. If they get to the login page any other way then it will just log them in normally. So far there are two pages that will have this special link, so two locations possible to go to from login rather than the normal home page. More could be added, so it needs to be something that is low maintenance and easy to add more pages to. I don't want it to always return to previous page on login though. Quote Link to comment https://forums.phpfreaks.com/topic/91284-how-could-i-do-something-like-this/#findComment-469607 Share on other sites More sharing options...
dave420 Posted February 18, 2008 Share Posted February 18, 2008 Personally, I'd use a session to store the user's page history as they move through your site. It's useful not just for things like this, but for building up a picture of how people move through your site. If on each page the page appends the current page's URL to, say, $_SESSION['history'], then the login.php page just has to check the last entry, and it knows that's where the user came from. It's invisible to the client, but lets you know exactly how the user got to where they are. If you use an auto_prepend_file, you can put the session history stuff in there, though remember that the login.php file will also count in that history, so it'll have to check for the penultimate entry in the history array, not the last one. Quote Link to comment https://forums.phpfreaks.com/topic/91284-how-could-i-do-something-like-this/#findComment-469696 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.