opel Posted November 6, 2006 Share Posted November 6, 2006 Still trying to learn some PHP and getting stuck again.I am trying to create a switch statement that looks at a URL and displays some HTML formated content. Below is what I have so far but I'm getting stuck on how to identify the URL as I have pages that start with the same word e.g news-list.php, news-detail.php and I would like the condition content to display for anything that starts "news".[code]<?phpswitch (condition) { case "header("Location: ../central/news");" :<p>This will be my content for the news section</p> break; case "header("Location: ../central/links");" :<p>This will be my content for the links section</p> break; default : <p>This will be my default message</p> break; }?>[/code]Thanks for any help or tips you can offer me. Link to comment https://forums.phpfreaks.com/topic/26267-switching-based-on-url/ Share on other sites More sharing options...
doni49 Posted November 6, 2006 Share Posted November 6, 2006 The header statement you're using will send the user to a NEW page://send user to www.mydomain.com/test.phpheader("Location: www.mydomain.com/test.php");You want to test against $_SERVER['php_self'] (that's the variable containing the URL of the current script file) and have a look at the following link:[url=http://www.php.net/eregi]www.php.net/eregi[/url] Link to comment https://forums.phpfreaks.com/topic/26267-switching-based-on-url/#findComment-120142 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.