Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/91284-how-could-i-do-something-like-this/
Share on other sites

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.

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.