$_self not working w/a dynamic page

<?php echo htmlentities ($_SERVER['$_SELF.PHP']);  ?>" method="POST">

From what i have read up self will automatically take the user to the index page, which is what is happening to me. Rather than showing the results on the "guestbook.inc.php file wich the code is on.
I tried

<?php echo htmlentities ($_SERVER['pages/guestbook.inc.php']);  ?>" method="POST">

(subbing the directory & file name)
but got a 403 error.
still searching for how to fix this. Anyone here has any suggestions or could point me to a good clear link?
Was looking at stack overflow but this guy’s answer had six or more line of codes and a new function to redirect the link. Thougth there would be a simpler solution?

You’re looking for $_SERVER[‘PHP_SELF’]

See also PHP $_SERVER superglobal documentation

Hey go Team Fortress (I play the scout, the heavy, doctor and sniper somtime. I die a lot in it…)
yes the ‘PHP_SELF’ was actually a typo on my part sorry.
My problem is that it work fine on its own page (guestbook.php). but when it is in page that is dynamic(guestbook.inc.php) that is called by index php. it doesn’t work. it takes me back to index php.
I need to find out how to make it post to the page it is on.

Perhaps the FILE constant, which points to the path of the currently executing file?

I am actually quite new at php.
would I place the FILE constat, & i’ll google that…in the place of ‘pages/guestbook.inc.php’ ?
<?php echo htmlentities ($_SERVER[‘pages/guestbook.inc.php’]); ?>

That FILE is surrounded by TWO underscores FILE and other PHP predefined constants.

Create a page with this in it and look carefully at the output.


echo 'These are your SERVER variables available from every script <hr />';


Hello Cups and thank you for your reply…but it did absolutely nothing.

You can also use <form method=“post”> (html5) or <form action=“” method=“post”> (html4) to make a form post to the current document’s URI.

Thank you Tom, but I am trying to learn php.

am I heading in the right way w/this?
<form action=“<?php pages(FILE).‘/guestbook.inc.php’; ?>” method=“POST”>

Did you save a file called server.php containing the code I showed you?

Put server.php in your document root then fire up this address:



Hello cups. Sorry I had not correctly understood you.
I tried again. created the file named it server.php same directory as the index file (not part of the dynamic pages) added the code

echo ‘These are your SERVER variables available from every script <hr />’;

when I run I get the “These are your SERVER variables available from every script” & a whole lot of of other info…like ““C:/xampp/htdocs” [“REQUEST_SCHEME”]=> string(4) “http” [“CONTEXT_PREFIX”]=> string(0) “” [“CONTEXT_DOCUMENT_ROOT”]=> string(15) “C:/xampp/htdocs” [“SERVER_ADMIN”]=> string(20) “postmaster@localhost” [“SCRIPT_FILENAME”]=> string(40) “C:/xampp/htdocs/phpjSRevw/php/server.php” [“REMOTE_PORT”]=> string(5) “61745” [“GATEWAY_INTERFACE”]=> string(7) “CGI/1.1” [“SERVER_PROTOCOL”]=> string(8) “HTTP/1.1” [“REQUEST_METHOD”]=> string(3) “GET” [“QUERY_STRING”]=> string(0) “” [“REQUEST_URI”]=> string(25) “/phpjSRevw/php/server.php” [“SCRIPT_NAME”]=> string(25) “/phpjSRevw/php/server.php” [“PHP_SELF”]=> stri”

i have no idea what to do with it.

$_SERVER is a built in array in PHP (http://php.net/manual/en/language.types.array.php). You can call one of these variables at any time. Say I need to get the current file that I am in, I can do this:


You’ll notice that the result is also located in the var_dump that you did.

A little pointer for the forums, please try to use the proper code highlighting when pasting stuff in here, makes things a lot easier on those who are trying to answer your question.

ok. will try it tomorrow,thank you much and promise to be more conscientious about using proper code tagging in the future!

Go back to your original post and you will see you were trying to access a SERVER variable that did not exist.

<?php echo htmlentities ($_SERVER['$_SELF.PHP']);  ?>" method="POST">

This showed that you did not know what you were doing.

The dump of SERVER variables you made now shows you all of the variables you can pick from, you can read them, echo them out onto the screen or use them to make strings for links etc.

You can do that var_dump($_SERVER) on any page you are developing on when you want to check which variables apply to that particular page.

Its really useful, its only one line, and you can comment it out or remove it before you publish the webpage – in fact you MUST – it contains lots of information that would be of interest to a potential cracker.

So now to return to the points made earlier in this thread you can edit that server.php page slightly and then compare the output of the following:


// comment out that readout, maybe uncomment it later ... else remove these lines
//echo 'These are your SERVER variables available from every script <hr />';

echo "The host for this site is " . $_SERVER['HOST'] . '<hr />';
echo "This exact script is " . $_SERVER['SCRIPT_FILENAME'] . '<hr />';
echo "The __FILE__ variable for this exact script is " . __FILE__ . '<hr />';

// now create some conditional messages depending on one of those variables ...

if($_SERVER['SCRIPT_FILENAME'] === "server.php"){

echo 'You have found the server vars page';


echo 'This is not the server vars page';


Well, I already knew I didn’t know what I was doing. If I did I wouldn’t have asked for help on a forum.
But will try this out. thanks.
As for the server variable that doesn’t exist…Again. I have the file it is there.
it work on its own. but not when called in a dynamic page settings.
The rather than posting text to itself it takes me back to the index file.