0
How do I show a message according to the URL the user is accessing?
For example:
Message:
You are on page A , when the url matches http://localhost/blog/home/a. php
You are on page B , when the url matches http://localhost/blog/home/b. php
0
How do I show a message according to the URL the user is accessing?
For example:
Message:
You are on page A , when the url matches http://localhost/blog/home/a. php
You are on page B , when the url matches http://localhost/blog/home/b. php
0
Using $_GET
To use this way you need to insert a variable in the link, or button that will redirect to the example page <a href="http://localhost/blog/home/a.php?Pag=a"
and recover used $_GET[]
$link = $_GET['Pag'];
if($link == a)
{
echo 'link a';
}else if($link == b)
{
echo 'link b';
}else{
echo 'error 404';
}
Using FILE
You can use the basename
to return the current.php file name
$path_parts = pathinfo( __FILE__ );
if($path_parts['basename'] == a.php)
{
echo 'pagina a';
}else if($path_parts['basename'] == b.php)
{
echo 'pagina b';
}else{
echo '404';
}
In your question __FILE__
meets your problem, but there are several other ways to use basename
to better understand how it works from a look at documentation
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; if($actual_link='http://localhost/blog/home/a.php'){ echo 'You are on the A page '; }Else{ echo 'You are on the B page '; }
– Helder Pereira
A simple method would be for you to insert a variable parameter at the end of the url
http://site.com?a.php?ADM
and retrieve this data with$_GET[]
this using php or also usingREQUEST_URI
, also has forms usingjavascript
, needs to be in pure php or can be using javascript?– WMomesso
using REQUEST_URI would be interesting to me could be in pure php even
– Smoke Rohden
Question: are separate files or are you rewriting the URL with .htaccess?
– Woss
are distinct files
– Smoke Rohden
So why do you need to identify the URL if you know which file is running? Just put in the file
a.php
which is on page A and in the archiveb.php
that is on page B. Or this message is in some code that is included in both?– Woss