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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.