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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Action based on Current URL

Status
Not open for further replies.

fuckoff222

Technical User
Mar 7, 2005
5
0
0
US
Hello All,

What I want to do is make a conditional action (IF) based on the current URL of where the user is on my website. If possible I would like it to be based on the relative web URL, for example /dir1/ , and not a server path. Also, I need the condition to be true in any other directories within this directory. So that anything with domain.com/dir1/ will cause this IF statement to be true.

Is there any way to do this? I looked around for a while and tried different things out, but I could not get anything to work.

Thanks a lot,
- Vince
 
PHP usually has the superglobal array $_SERVER which contains the information you are looking for. The info is web server specific, I just can speak from my experience with Apache.
Write a few lines and inspect the vars and how they change with the URL:
Code:
<?php
echo "<pre>";
print_r($_SERVER);
echo "</pre>";
?>
Look at SCRIPT_URL. A substr() or strpos() is the best way to examine the string for presence of the desired 'needle'
 
Okay if this were Java I would be done by now. But PHP just seems really cumbersome at times. The REQUEST_URI element in the _SERVER array returns the relative document server path, including the filename. So instead of /dir/dir2, it gives me /dir/dir2/file.ext . How can I get rid of the filename, and just get the current directory? There doesn't seem to be a variable that just gives the current directory name without the filename at the end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top