0

I need to create some if else statements depending on what page user is, I tried looking for this in php manual, but didn't find anything useful.

Basically what I want is a syntax for something like:

if (user is on a page index.php)

 $message = $_GET["title"];
 if $message = "hello";
 $say = "Hello";

etc ....

Can anyone show how this can be done?

Ilja
  • 40,784
  • 74
  • 242
  • 455
  • possible duplicate of [How to get URL of current page in PHP](http://stackoverflow.com/questions/1283327/how-to-get-url-of-current-page-in-php) – jprofitt Dec 16 '11 at 17:37
  • @jprofitt it may not be a duplicate. If the URI requested is redirected in some way by the server, PHP may be processing a different file than what the URI seems to be pointing at. – CLo Dec 16 '11 at 17:45

3 Answers3

3

Try looking at _SERVER[REQUEST_URI], _SERVER[SCRIPT_NAME], _SERVER[SCRIPT_FILENAME], _SERVER[PHP_SELF], and possibly others.

Explosion Pills
  • 183,406
  • 48
  • 308
  • 385
  • 1
    http://www.php.net/manual/en/reserved.variables.server.php A full list of Server values, also you can use the __FILE__ constant as listed on that page. SO makes it bold but there are two underscores before and after FILE. – CLo Dec 16 '11 at 17:40
1

you can use a session variable to track the user: every page is opened set a session variable to it's name so you can know what is the last opened page

Zorb
  • 728
  • 11
  • 24
  • This requires similar but different code on every page with a constant value for the name. Also, if the file name changes for any reason you'd have to go back in and edit it. – CLo Dec 16 '11 at 17:40
  • may be i miss understood the question, i ti the right answer if you want to know on what page of your site certain user is – Zorb Dec 16 '11 at 17:40
  • I don't think sessions are necessary. – Ilja Dec 16 '11 at 17:41
  • yes, you are right, should i delete the answer? (while now is not responding to the user question) – Zorb Dec 16 '11 at 17:44
0

x = str_replace('.php', '', (end(explode('/',HttpRequest::getUrl))));

Toping
  • 758
  • 5
  • 16