PDA

View Full Version : How do I do this in PHP




D0ct0rteeth
Sep 18, 2005, 05:25 PM
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
%>



belvdr
Sep 19, 2005, 11:19 AM
Use _SERVER['REQUEST_URI']

Documentation here (http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server)

mnkeybsness
Sep 19, 2005, 06:54 PM
This is pretty dirty, but it should give you the idea...

<?php
$uri = $_SERVER['REQUEST_URI'];
$url = explode("/",$uri);

$url = $url[1];

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

belvdr
Sep 19, 2005, 08:17 PM
This is pretty dirty, but it should give you the idea...

<?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;
}
?>