0

recently i came across strange problem while uploading files to my new server.

I am using $_SERVER['REQUEST_URI'] to find the current page location and add some param and redirect as following:

<a href="<?php echo $_SERVER['REQUEST_URI'].'&action=edit&uin=1';?>">Edit</a>

It works fine in my local computer and redirects to my page :

localhost/admin/home.php?module=Pages&action=edit&uin=1

and my tag:

<a href="http://localhost/sitename/admin/home.php?module=Pages&action=edit&uin=1">Edit</a>

but in my testing server it generated url without servername so it became like:

<a href="http://admin/home.php?module=Pages&action=edit&uin=1">Edit</a>

and redirected to : http://admin/home.php?module=Pages&action=edit&uin=1 resulting redirect to invalid page...

So wondering which server setting is creating that difference?

And how can we solve it? both resulting same

KoolKabin
  • 17,157
  • 35
  • 107
  • 145

1 Answers1

2

The PHP documentation can tell you the difference:

'PHP_SELF'

The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The FILE constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.

'SCRIPT_NAME'

Contains the current script's path. This is useful for pages which need to point to themselves. The FILE constant contains the full path and filename of the current (i.e. included) file.

'REQUEST_URI'

The URI which was given in order to access this page; for instance, '/index.html'

Community
  • 1
  • 1
xkeshav
  • 53,360
  • 44
  • 177
  • 245