LZ1
asked on
PHP Conditional on part of URL
Hey Experts!!
I need to have a conditional statement based on a URL. But, I only need the www.mydomain.com part of the URL. Anything pre or post that part is irrelevant.
I'm poking around in PHP so please be gentle. Any and all help is appreciated!!
I need to have a conditional statement based on a URL. But, I only need the www.mydomain.com part of the URL. Anything pre or post that part is irrelevant.
I'm poking around in PHP so please be gentle. Any and all help is appreciated!!
Please do us a favor - post the test case data, OK? What are we starting with here? Thanks, ~Ray
And then tell us what kind of conditions to look for.
This may be something we can do with REGEX or with some combination of string functions.
This may be something we can do with REGEX or with some combination of string functions.
ASKER
Sorry for the incomplete question Ray.
Actually the only code I have is getting the current page URL, which is below.
This is basically what I need:
if PageURL contains abc.com
echo ('image')
elseif PageURL contains xyz.com
echo('image2')
Actually the only code I have is getting the current page URL, which is below.
This is basically what I need:
if PageURL contains abc.com
echo ('image')
elseif PageURL contains xyz.com
echo('image2')
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
ASKER
I came across this. Not sure if it's useful or not.
<?php
if (substr($_SERVER['REQUEST_URI'], 7, 15) == 'mydomain.com') {
echo 'We should see this if we are on mydomain.com';
}
?>
ASKER
I think I have it.
I came up with this by searching for a string inside of the URL. If anyone sees room for improvement, please let me know!!
I came up with this by searching for a string inside of the URL. If anyone sees room for improvement, please let me know!!
<?php
$url = $_SERVER['HTTP_HOST'];//gets current page url
if (stristr($url, 'mydomain1.com') == true)
echo ('<a href="http://mydomain.com/">
<img src="http://content-1.s3.amazonaws.com/images/skis/tag-cloud.jpg" alt="Save On Packages" title="Save On Packages" width="250px"/>
</a>');
elseif(stristr($url, 'mydomain2.com') == true)
echo "Womens Skis are better ";
elseif(stristr($url, 'mydomain3.com') == true)
echo "SNOWBOARDS.NET";
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect Ray! Thanks!
Thanks for the points - excellent question, ~Ray