Forum Moderators: coopster

Message Too Old, No Replies

Setting variable based on page requested.?

         

nfs2

3:08 pm on Apr 12, 2006 (gmt 0)

10+ Year Member



I'd like to set a variable based on the page or directory requested. So if sombody went to mysite.com/hello i'd want to set a variable like;

if ($_SERVER['something'] == "/hello") {

$var = 'something';

}

I thought $_SERVER['REQUEST_URI'] would do it, but it doesn't..

sned

4:01 pm on Apr 12, 2006 (gmt 0)

10+ Year Member



Do you mean the page the user came from? Or the page the user is currently at?

If you mean the referring page, try $_SERVER['HTTP_REFERER']

If you mean the second option, try $_SERVER['PHP_SELF']

-sned

nfs2

4:35 pm on Apr 12, 2006 (gmt 0)

10+ Year Member



Well. technically neither of those.. Not exactly, but closer to the second one..

What i mean is, if im at example.com/foo/dir?bla=bar then $_SERVER['PHP_SELF'] would equal example.com/foo/dir?bla=bar. I just want to set a variable in the header for the directory /foo/

JohnCanyon

1:00 am on Apr 13, 2006 (gmt 0)

10+ Year Member



then why not simply do something like the following.

if(preg_match("/foo/i",$_SERVER['REQUEST_URI']))
{
//you are in directory /foo
}
else
{
//your not
}

Now obviously you can manipulate the simple example above to better suit your needs.

Cheers,

J

nfs2

1:56 am on Apr 13, 2006 (gmt 0)

10+ Year Member



Thanks, that worked great :)