Forum Moderators: coopster

Message Too Old, No Replies

include file to control elements in static php pages

         

php4U

3:58 am on Aug 2, 2008 (gmt 0)

10+ Year Member



I can use the following to control elements in pages that use query strings such as: index.php?page=about
<?php
$request = $_SERVER['REQUEST_URI'];
if (isset($_GET['page']) && $_GET['page'] == 'about') { /* see if ?page is present and if it is equal to "about" */
echo '<span style="color: red; font-weight: bold;">About Us</span>';
}
else {
echo '<a href="?page=about" class="menu">About Us</a>';
}
?>

I don't work on many sites that use seperate pages like about.php contact.php and so on, but I have a question about if the above code can be modified to work on static pages.

I would like to see if that code could be changed to work in the same way so one include file can be inserted and for instance...keywords, descriptions, so on could be supplied based on domain.com/about.php

I tried to mess around with that code to get the request of a static page like about.php but didn't have any luck.

A general idea...
$request = $_SERVER['REQUEST_URI'];

somehow check that if $request equals domain.com/about.php
echo "keyword, keyword 1, keyword 2"; (can be anything really...specific to that page..graphics etc.)

Of course you can have http, https, w/ or w/o www. so domain.com/about.php would cover most. Thank you for any help, just a little curious.

PHP_Chimp

6:54 pm on Aug 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use a regex or explode to split apart your url. You could also have a look at parse_url [uk3.php.net] as you could get the path from that easily.
So then you can use if ($path == to get what you want.

php4U

2:00 am on Aug 6, 2008 (gmt 0)

10+ Year Member



Thank you for the suggestion PHP_Chimp I will look into that.

eelixduppy

2:38 am on Aug 6, 2008 (gmt 0)



Check grab the script name...

$name = $_SERVER["PHP_SELF"];
#
switch($name) {
case '/about.php':
echo 'something';
break;
case 'another_page.php':
echo 'something else';
break;
etc...
}

I don't see why you would need to use any string parsing here unless I'm not understanding.