Can you check for a term within a URL?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Can you check for a term within a URL?

Post by simonmlewis »

We need to prevent part of a page showing if logged in - which will also have a_ within the URL.

ie. /fred/a_add

How do I check if "a_" is in the URL?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you check for a term within a URL?

Post by simonmlewis »

Haha, just worked it out myself, from using a means of removing something from the URL before:

Code: Select all

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;
}
$url = curPageURL();
if (strpos($url,'a_') === false) {
$disablefooter = "y";
}
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Can you check for a term within a URL?

Post by requinix »

By the way,

Code: Select all

if ($_SERVER{"HTTPS"] == "on" && $_SERVER["SERVER_PORT"] != 443 || $_SERVER["HTTPS"] != "on" && $_SERVER["SERVER_PORT"] != 80) {
Otherwise you'll be adding :443 for HTTPS URLs.
Post Reply