If (If X Page redirect me here)
{
run this code
}
else
{
run this code
}
What to write in IF condition? What is the PHP Code?
If (If X Page redirect me here)
{
run this code
}
else
{
run this code
}
What to write in IF condition? What is the PHP Code?
Try $_SERVER variable
<?php
echo '<pre>';
print_r($_SERVER);
?>
Output (on phpfiddle.org)
Array
(
[DOCUMENT_ROOT] => /home/xfiddlec/public_html/main
[EE_HOST] => main.xfiddle.com
[EE_LIB] => /home/xfiddlec/public_html/main/inclibs/
[EE_LIB_PREFIX] => /home/xfiddlec/public_html/main/inclibs/
[EE_ROOT] => /home/xfiddlec/public_html/main/
[GATEWAY_INTERFACE] => CGI/1.1
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5
[HTTP_CONNECTION] => close
[HTTP_HOST] => main.xfiddle.com
[HTTP_REFERER] => http://phpfiddle.org/
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_USER_AGENT] => Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
[HTTP_X_FORWARDED_FOR] => 157.49.9.71
[HTTP_X_REAL_IP] => 157.49.9.71
[PATH] => /bin:/usr/bin
[PHPRC] => /home/xfiddlec/config
[PROXY_ADDR] => 31.22.4.102
[QUERY_STRING] =>
[REDIRECT_STATUS] => 200
[REMOTE_ADDR] => 157.49.9.71
[REMOTE_PORT] => 56471
[REQUEST_METHOD] => GET
[REQUEST_URI] => /code_45646358.php
[SCRIPT_FILENAME] => /home/xfiddlec/public_html/main/code_45646358.php
[SCRIPT_NAME] => /code_45646358.php
[SERVER_ADDR] => 31.22.4.102
[SERVER_ADMIN] => webmaster@www.main.xfiddle.com
[SERVER_NAME] => main.xfiddle.com
[SERVER_PORT] => 80
[SERVER_PROTOCOL] => HTTP/1.0
[SERVER_SIGNATURE] =>
Apache Server at main.xfiddle.com Port 80
[SERVER_SOFTWARE] => Apache
[SITE_WEBMASTER] => PhpFiddle Webmaster
[SITE_WEBMASTER_URI] => mailto:webmaster@xfiddle.com
[TZ] => America/New_York
[UNIQUE_ID] => WRaD3x8WBGYADWv4OMgAAAAN
[PHP_SELF] => /code_45646358.php
[REQUEST_TIME_FLOAT] => 1494647775.2
[REQUEST_TIME] => 1494647775
[argv] => Array
(
)
[argc] => 0
)
You can use following value in if condition
if ( $_SERVER[HTTP_REFERER] == "some thing" ) {
// do my job
} else {
// do another job
}
Or You can pass some GET/POST parameters and check their existence in php page.
In your X page
If you navigating using anchor html
<a href="y.php?from_page=x" >y page</a>
(or) If your redirecting using php header()
header('Location:y.php?from_page=x');
In Y page
php
if(isset($_GET['from_page']) && $_GET['from_page']=='x')
{
echo "run this code ";
}
else
{
echo " run this coe ";
}