Jump to content

Recommended Posts

I have been going through a tutorial. It is a tutorial for PHP 4. I have PHP 5 installed on my PC. I have read that the $_SERVER[PHP_SELF] is not supported in PHP 5.

If I am not mistaken that tells the server to run the next PHP script on the page when a certain condition is met. My question is, If it is not supported in PHP 5 then how do you tell it to run the next script on the page?

I'm sorry if my question is not clear. I am a newbie teaching myself. I can give an example of the code I am talking about if needed. I got it to work by uploading it to my site that supports PHP 4 as well. It takes the PHP_SELF.

Any help appreciated!!
Link to comment
https://forums.phpfreaks.com/topic/9974-php_self-and-php-5-question/
Share on other sites

[img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] No that isn't what it means, but thats cool. I was a noobie teaching myself once, also [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] . $_SERVER['php_self'] means it will echo the url.. I cant remember if it will echo the full path (yourdomain.com/path/script.php), or the path and script (/path/script.php), or just the script (script.php). Here is a prime example of how I use it.

First I start off with an if statement. If submit has a value to it, then I run the script in the if statement. if not i go on down the page to a form script. the form you fill out and hit submit. the form action is:

<?php
echo '<form action="$_SERVER[php_self]">';
?>

or something like that. Anyways, that means that when the submit button is hit it will reload the page it is currently on, or the form will reload itself carrying the values with it to be excuted within the if statement.

Hope that clear things up. Here is a helpful link:

[a href=\"http://us2.php.net/reserved.variables\" target=\"_blank\"]http://us2.php.net/reserved.variables[/a]
i did a quick test on my host and it displayed the following with $_SERVER['PHP_SELF'] and $PHP_SELF

/test.php


but i think it depends on your php settings as to how the url is stored.

if you need to find out and you don't wanna mess with the settings then just do

echo $_SERVER['PHP_SELF'];

or

echo $PHP_SELF;

[!--quoteo(post=375120:date=May 19 2006, 04:12 AM:name=PCB guy)--][div class=\'quotetop\']QUOTE(PCB guy @ May 19 2006, 04:12 AM) [snapback]375120[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I have been going through a tutorial. It is a tutorial for PHP 4. I have PHP 5 installed on my PC. I have read that the $_SERVER[PHP_SELF] is not supported in PHP 5. [/quote]
That is completly wrong.

PHP does support the PHP_SELF server variable. Now PHP will only out put something when using $_SERVER['PHP_SELF'] or any other superglobal array variables if register_globals is turned off on the server, But you can sitll use PHP_SELF but you call it this way instead: $PHP_SELF, basically you use the index/key of the superglobal array as the variable instead when register_globals is turned on.

And no PHP_SELF does not call the next php script but it gets the filename of the currently executing script, relative to the document root. Oh ghers a link for information about [a href=\"http://uk.php.net/manual/en/security.globals.php\" target=\"_blank\"]regsiter_gloabls[/a].
Here is the example the tutorial gave:

<?php
if (!$_POST['submit'])
{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Enter a number: <input name="number" size="2">
<input type="submit" name="submit" value="Go">
</form>
<?php
}
else
{

$number = $_POST['number'];
if ($number > 0)
{
echo 'You entered a positive number';
}
elseif ($number < 0)
{
echo 'You entered a negative number';
}
else
{
echo 'You entered 0';
}
}
?>

Okay. If the submit button is pressed then the $_SERVER['PHP_SELF'] tells it to continue the script on the same page. It basically points to itself, right? The question is if the register_globals are set to off in PHP5 then what would replace this bit of code to make it do the same thing in PHP5?

I love these forums. You have all been a big help.

Be easy on me. Maybe I am making it harder than it is.
If it register_globals is [b]off[/b] then you use $_SERVER['PHP_SELF']

But if register_globals is [b]on[/b] you'll use $PHP_SELF


Prehaps I didn't explain it very well in my last post? PHP5 has register_globals turned off by defualt, well it should be unless you or your webhost has turned it on.

I see you are using [b]<?=$_SERVER['PHP_SELF']?>[/b] I would chnage that to [b]<?php echo $_SERVER['PHP_SELF']; ?>[/b] instead as not all servers are configured to use the <?= ?> tags.
Okay. That is what I needed. I think. I would use the <?php echo $_SERVER['PHP_SELF']; ?> on place of the other because my globals are off by default.

Thanks so much. I read that it wouldn't work with PHP5 but the tutorial didn't say how to do it another way. I looked up 2 more tutorials last nite that said PHP5 on them but had the same example.

Thanks so much for your help.
also, it does not [i]continue[/i] the script.. it reloads the entire page, so all things that you have before it will be executed again. that is why you need to have everything inside a condition that is based on whether the submit button has been pressed, or whatever.
It is making sense now. I am not much of a programmer. I taught myself HTML and thought I would learn PHP and MySQL to enhance my web design knowledge. I've found PHPfreaks to be the best source of information.

I'm sure I will have more questions.

Is everyone here self taught?
it's been my experience that most people who know php are 'self-taught.' why? because it's completely free to learn and implement, so it's the ideal thingie for people with no cash. Plus PHP is so cool it's even sexy cool [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]
I have self-taught myself too. It doesn't cost any $$$ when learning PHP unless you pay for a book or go on a training course. With the basics of PHP in your head you should be able to create something simple. Like an email form or a very simple shoutbox/guestbook. Thats how I learnt PHP.

The best place to go is ofcouse [a href=\"http://www.php.net\" target=\"_blank\"]http://www.php.net[/a] in order to ubderstand how to use/understand a function, or variable etc.
To be honest, i do not think the manual is helpful at all for people who have never programmed before. The manual assumes you already understand programming concepts in general. It's not a "for dummies" resource - which is great, because it is thorough - but not for beginners.

if you are new to programming in general and you are wanting to get into php then places like phpfreaks.com is the place to go [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

well i personally went to the bookstore and bought a book called "php in easy steps."

[a href=\"http://www.ineasysteps.com/books/details/?1840782072\" target=\"_blank\"]http://www.ineasysteps.com/books/details/?1840782072[/a]

It teaches you all the basics, and at 10 bucks, you can't beat that. Of course, that's just my own opinion. Most people will say they refuse to buy a tutorial book when you can find lots of tutorials online for free. Well I don't like having lots of different screens open, especially when I'm trying to learn something, so 10 bucks was worth it. Also, I have found it a lot easier to bring a book into the bathroom to read, rather than drag my entire computer. "use your time efficiently" my pops always told me [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

The Sam's Teach Yourself [i]x[/i] in [i]y[/i] Days, etc., series are all excellent books - in this case, there's [b]Sam's Teach Yourself PHP, MySQL, and Apache in 24 hours[/b].

I got started using Jason Gilmore's [i]PHP 5 and MySQL: From Novice to Professional[/i], and once I learned the basics, I used the PHP manual.
yeh that's why i went for the cheap teach you the basics book. since php is constantly being updated, getting a full fledged book will quickly become obsolete.. i definatley agree with turning to the manual after you learn the basics. that's pretty much the only php source I use now.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.