Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An if statement based on what the url contains 1

Status
Not open for further replies.

gameon

Programmer
Feb 23, 2001
325
GB
Hi, usually I use ColdFusion, but at the mo it has to be php.

For navigation - I usually use the following to make naviagtion maintainance easier.

if the url contains "a string"

do this:

else do this:

Can someone help me do this with php?

Cheers if you can illuminate me...

M@)
 
If I understand correctly, you want to use the URL of the current page.

If this is the case, PHP has predefined variables that you can use:

$PHP_SELF will contain the URL relative to the site. For example: /index.php

$HTTP_REFERER (yes, 'referer' is misspelled) will contain the full Internet URL. For example:
You could then run a preg_match() to perform a regexp match on the value of $PHP_SELF or $HTTP_REFERER and define your conditional statement.

if (preg_match ("/regexp_goes_here/", $PHP_SELF)) {
do_something;
} else {
do_something_else;
}

If you found this post helpful, please click the appropriate link below to mark it as such. Thanks!
 
Hi BLawson, in the end I used:

<?php
if(stristr($HTTP_SERVER_VARS[REQUEST_URI],&quot;/~mattg/registration/&quot;)){
print &quot;<img src=\&quot;/~mattg/images/left_nav/down/registration.gif\&quot; border=\&quot;0\&quot; width=\&quot;173\&quot; height=\&quot;13\&quot; alt=\&quot;Registration\&quot; name=\&quot;\&quot; onMouseOut=\&quot;MM_swapImgRestore()\&quot; onMouseOver=\&quot;MM_swapImage('registration','','/~mattg/images/left_nav/over/over_registration.gif',1)\&quot;>&quot;;
}else{
print &quot;<img src=\&quot;/~mattg/images/left_nav/up/registration.gif\&quot; border=\&quot;0\&quot; width=\&quot;173\&quot; height=\&quot;13\&quot; alt=\&quot;Registration\&quot; name=\&quot;registration\&quot; onMouseOut=\&quot;MM_swapImgRestore()\&quot; onMouseOver=\&quot;MM_swapImage('registration','','/~mattg/images/left_nav/over/over_registration.gif',1)\&quot;>&quot;;
}?>

Do you think is is ok?

M@
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top