Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

D0ct0rteeth

macrumors 65816
Original poster
Mar 11, 2002
1,239
7
Franklin, TN
I am looking to create a slightly different nav for each section on my site. I need PHP to look at the URL and see if the Folder is /AboutUs/ or /Services/ or whatever...

I have it working in ASP. How do I do it in PHP?






<%
vURL = mid(Request.ServerVariables("PATH_INFO"),2,999)
vSlashPlace = Instr(1, vURL, "/")
if vSlashPlace>0 then vURL = left(vURL, vSlashPlace-1)

if vURL = "Home" then

%>

HTML code goes here

<%

elseif vURL = "AboutUs" then

%>

HTML code goes here

<%

elseif vURL = "Services" then

%>

HTML code goes here

<%

elseif vURL = "ContactUs" then

%>

HTML code goes here

<%

else

%>

HTML code goes here

<%

End if
%>
 

mnkeybsness

macrumors 68030
Jun 25, 2001
2,511
0
Moneyapolis, Minnesota
This is pretty dirty, but it should give you the idea...
Code:
<?php
$uri = $_SERVER['REQUEST_URI'];
$url = explode("/",$uri);

$url = $url[1];

if($url == 'home'){
?>
HTML
<?php } elseif($url == 'about') { ?>
HTML
...
<?php } elseif...
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
mnkeybsness said:
This is pretty dirty, but it should give you the idea...
Code:
<?php
$uri = $_SERVER['REQUEST_URI'];
$url = explode("/",$uri);

$url = $url[1];

if($url == 'home'){
?>
HTML
<?php } elseif($url == 'about') { ?>
HTML
...
<?php } elseif...

Or, some like the switch statement:

Code:
<?
switch ($url) {
case "home":
   ?> HTML <?
   break;
case "about":
   ?> HTML <?
   break;
case "whatever else":
   ?> HTML <?
   break;
}
?>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.