Jump to content

[SOLVED] simple php help


champrock

Recommended Posts

[code=php:0]<?php
if ($pageURL === "abc.com" ||  "xyz.com" || "pqr.com" || "aer.com")
  {
echo 'something';
}
?>

[/code]

helo.

 

i am looking to create some snippet which basically does the following work

1. the $pageURL string contains this $_SERVER["SERVER_NAME"] (the domain of the page)

2. i want to match it up with few matches and output something in particular if the $pageURL is same as the above four matches. and not echo anything when $pageURL is different from the above 4.

 

but when i am using this code, it is echoing "something" in every domain, even in lets say "blahblah.com" and "tommy.com".  the logical comparison is not working :(

 

 

any suggestions where i am going wrong?

Link to comment
https://forums.phpfreaks.com/topic/100258-solved-simple-php-help/
Share on other sites

<?php

if ($pageURL == "abc.com")
{
     echo 'something if domain is abc.com';
}
elseif ($pageURL == "xyz.com")
{
     echo 'something if domain is xyz.com';
}
elseif ($pageURL == "pqr.com")
{
     echo 'something if domain is pqr.com';
} else
{
     echo 'something if domain is none of the above';
}

?>

To do it your way you would need....

 

<?php
if ($pageURL == "abc.com" ||  $pageURL == "xyz.com" || $pageURL == "pqr.com" || $pageURL == "aer.com") {
 echo 'something';
}
?>

 

A better solution....

 

<?php
if (in_array($pageURL,array("abc.com","xyz.com","pqr.com","aer.com")) {
 echo 'Something';
}
?>

thanks a lot for ur prompt reply.

 

<?php
if (in_array($pageURL,array("abc.com","xyz.com","pqr.com","aer.com")) {
  echo 'Something';
}
?>

i am using this code, but this still does not work. i dont know why but it is still showing "something" for domains which are not in that array. any way to make it case-insensitive?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.