Show message according to URL

0

How do I display a message according to the URL that the user is accessing?

For example:

Message:
You are on page A, when the url matches link
You are on page B, when the url matches link

    
asked by anonymous 13.10.2017 / 16:24

1 answer

0
  

Using $ _GET

To use this way you need to insert a variable in the link, or button that will redirect to the sample page <a href="http://localhost/blog/home/a.php?Pag=a" and retrieve 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 basename to return the name of the current .php file

$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__ addresses your problem, but there are several other ways to use basename to better understand how a look at documentation

    
13.10.2017 / 17:04