Reputation: 133
Hi i'm trying to think of a way that if a user clicks a certain link it takes them to a new page where only if the user has come from that parent link it will echo a statement on the newly opened page?
Is this possible and if so does anyone know how i could do it? Thanks
Upvotes: 0
Views: 795
Reputation: 1497
I don't know if I understood your question correctly but give this a try...
HTTP_REFERER
could help you do this but it isn't really reliable.
<?php
$referer = $_SERVER['HTTP_REFERER'];
$referer_parse = parse_url($referer);
if($referer_parse['host'] == "yoursite.com" || $referer_parse['host'] == "www.yoursite.com")
{
//from expected page
//echo here
} else {
//not from expected page
//do something else
}
?>
NOTE
This is a sample code showing the logic, you'll still need to modify this to fit your needs.
INFO
I would suggest trying to find a way/logic to implement it with the use of secret/session keys.
Good luck,
Madz
Upvotes: 1
Reputation: 9823
If I understood the question correctly
<a href="abc.php?link=1">Link 1</a>
<a href="abc.php?link=2">Link 2</a>
<a href="abc.php?link=3">Link 3</a>
Then in abc.php
$link = $_GET['link']; // Don't forget to sanitize the data
if($link == 1)
{
// user clicked Link 1
}
else if($link == 2)
{
// user clicked Link 2
}
else if($link == 3)
{
// user clicked Link 3
}
else
{
// came from somewhere else; i.e. did not click the links
}
Upvotes: 0