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
  • 44,142
  • 92
  • 275
  • 498
  • @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

4 Answers4

2

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

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • 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
0

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
  • 726
  • 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
-1

Current Url :

$currenturl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Curren File: $_SERVRER['SCRIPT_FILENAME']

-1

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

Toping
  • 754
  • 5
  • 16