Page 1 of 1

Detecting the URL and choosing a statement.

Posted: Sun Jun 08, 2008 2:51 pm
by Master_Phantom
Hi comm,

First I´m a bit new in PHP but I understand it well.

I´m going to tell what is my objetive:

I have a site that I want to show in the index "a.jpg" and in the other pages "b.jpg"

For example I want something like this:

Code: Select all

 <?php
 
if (myURL == "http://mydomain.com/index.php"){
 
echo ("<div align='center'><img src='a.jpg'>");
 
} else {
 
echo ("<div align='center'><img src='b.jpg'>");
 
?> 
The problem is that I need how to get the URL into a variable. :cry:

Thanks for advance

Greetings

Master Phantom

Re: Detecting the URL and choosing a statement.

Posted: Sun Jun 08, 2008 3:00 pm
by hansford
$myUrl = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

Re: Detecting the URL and choosing a statement.

Posted: Sun Jun 08, 2008 3:01 pm
by Johnlbuk
Hi,

You can use the following CurlPageName function and then use an if statement. This just fetches the page name so you can use it without knowing the domain to use it on.

Code: Select all

<?php
function curPageName() {
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
 
$pagename = curPageName();
 
if ($pagename == "index.php"){
 
echo ("<div align='center'><img src='a.jpg'>");
 
} else {
 
echo ("<div align='center'><img src='b.jpg'>");
 
}
?>
This will work for you!
John

Re: Detecting the URL and choosing a statement.

Posted: Sun Jun 08, 2008 3:06 pm
by Master_Phantom
Woooooow,

Thanks a lot, you´re very quick, I´m going to test it right now.

Thanks again :D

A++

Master Phantom

Re: Detecting the URL and choosing a statement.

Posted: Sun Jun 08, 2008 3:08 pm
by Johnlbuk
No problem.
If you need any further assistance let me know.

John