Jim
Jim

Reputation: 191

Difference between: $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF']

What is the difference between:

$_SERVER['SCRIPT_NAME']

and

$_SERVER['PHP_SELF']

Thank you.

Upvotes: 19

Views: 24597

Answers (2)

Michael Irigoyen
Michael Irigoyen

Reputation: 22947

They should contain the same information. However, historically and technically speaking, there is a difference between the two.

SCRIPT_NAME is defined in the CGI 1.1 specification, and therefore is a standard. This means it should be available no matter what scripting language you're using.

PHP_SELF is implemented directly by PHP, and as long as you're programming in PHP, it will be there.

Upvotes: 12

regilero
regilero

Reputation: 30496

Most of the time it's the same, but $_SERVER['SCRIPT_NAME'] is less spoofable than $_SERVER['PHP_SELF'], so you should use SCRIPT_NAME if you want to reuse that data somewhere on your output.

Check that article on different results obtained.

Upvotes: 8

Related Questions