954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Undefined variable: PHP_SELF

I think I've done what's necessary to install mod_php in Apache, but this code fails:

----------modtest.php
<?php echo $PHP_SELF?>
------------------------

When I display modtest.php in a browser, I get:

Notice: Undefined variable: PHP_SELF in C:\Program Files\Apache Group\Apache2\htdocs\modtest.php on line 1

I've read in docs that this env var doesn't exist in the comand line version, which I've verified is working because displaying this page is successful:

-------------printinfol.php
<?php echo 'This is my first PHP web page.' ?>
-------------------------

I have this line in my http.conf file:

LoadModule php5_module "c:/php/php5apache2.dll"

and verified that file exists in that directory. Did I miss something to get mod_php to work?

Using Apach2 in WinXP Home with php5.

Thanks in advance!

techhelpforme
Light Poster
29 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

The website that told you to use $PHP_SELF is severely out of date. Instead, use $_SERVER['PHP_SELF']

Roberdin
Supreme Evil Overlord
Team Colleague
282 posts since Feb 2003
Reputation Points: 63
Solved Threads: 6
 

Thanks Roberdin, you rock!

BTW, the "out-of-date source" is a university professor, and this is par for his course. :(

Just so I'm clear, is PHP_SELF deprecated for all versions of PHP or just windows versions?

techhelpforme
Light Poster
29 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

I did a quick google search and came up with this off of phpfreaks.com: $PHP_SELF should not be used because it will not work without register_globals being enabled. Rather, you should use $_SERVER['PHP_SELF'] for it.

cscgal
The Queen of DaniWeb
Administrator
19,432 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
 

I think I've done what's necessary to install mod_php in Apache, but this code fails:

----------modtest.php <?php echo $PHP_SELF?> ------------------------

When I display modtest.php in a browser, I get:

Notice: Undefined variable: PHP_SELF in C:\Program Files\Apache Group\Apache2\htdocs\modtest.php on line 1

I've read in docs that this env var doesn't exist in the comand line version, which I've verified is working because displaying this page is successful:

-------------printinfol.php <?php echo 'This is my first PHP web page.' ?> -------------------------

I have this line in my http.conf file:

LoadModule php5_module "c:/php/php5apache2.dll"

and verified that file exists in that directory. Did I miss something to get mod_php to work?

Using Apach2 in WinXP Home with php5.

Thanks in advance!


Method 1// try to close error message from php in php.ini
Method 2// try to use $_SERVER['PHP_SELF'] instead of $PHP_SELF

thinnakornzhang
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You