Jump to content

Switching based on URL


opel

Recommended Posts

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]<?php
switch (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

The header statement you're using will send the user to a NEW page:

//send user to www.mydomain.com/test.php
header("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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.