Show message according to URL

Asked

Viewed 79 times

0

  • $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 '; }

  • 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 using REQUEST_URI, also has forms using javascript, needs to be in pure php or can be using javascript?

  • using REQUEST_URI would be interesting to me could be in pure php even

  • Question: are separate files or are you rewriting the URL with .htaccess?

  • are distinct files

  • 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 archive b.php that is on page B. Or this message is in some code that is included in both?

Show 1 more comment

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 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

You are not signed in. Login or sign up in order to post.