Undefined Variable PHP_SELF

2019-03-18 13:23发布

问题:

I am developing a backend with php here.

I am having problem with such error like this:

Undefined variable : PHP_SELF

on my htdocs directory.

I'm developing with php 5.4.4 , and if you want to look at the source code here it is:

http://pastebin.com/xr2PxbNG

回答1:

Do not use any of the suggested versions of PHP_SELF. It is a security nightmare, opening up your PHP to a multitude of possible injection attacks.

What are you trying to achieve? Generate the URL for a form sending to itself? Use action="" for that - it is a valid approach and will always use the URL for sending the form as for loading.

If you must know the requested script, use $_SERVER['SCRIPT_NAME'] instead.



回答2:

You are using $PHP_SELF it should be

echo $_SERVER['PHP_SELF'] ;

Or

$PHP_SELF = &$_SERVER['PHP_SELF'];
echo $PHP_SELF ;

You can also have

define("PHP_SELF",$_SERVER['PHP_SELF']); 
echo PHP_SELF ;


回答3:

Are you trying to access $_SERVER['PHP_SELF'] ?



回答4:

It is $_SERVER['PHP_SELF'], not $PHP_SELF. See the docs



回答5:

Looks like certain WordPress distributions declare $PHP_SELF = $_SERVER['PHP_SELF'] for reasons I can't say, must be some sorta legacy thing.



回答6:

I have to Solve This Error Using Page Url... Ex. Like

echo "<a href=\"$_PHP_SELF?page=$last\">Last 3 Records</a>";

You Have to remove $_PHP_SELF and use page URL insert.php .......



回答7:

I was getting the same, Notice: Undefined variable _PHP_SELF So I just replaced $_PHP_SELF to $_SERVER[PHP_SELF] Now I don't get any extra no



回答8:

Some shells will erase the value of $_SERVER['PHP_SELF'] as a security measure. You may need to look at $_SERVER['argv'][0] if this is what is happening to you.



回答9:

I solved starting the variable:

$PHP_SELF = NULL;
$Path1 = realpath(substr($PHP_SELF, 1));
$dbName = "$Path1\\BD.accdb";