Jump to content


Photo

PHP_SELF and PHP 5 question


  • Please log in to reply
15 replies to this topic

#1 pcbguy

pcbguy
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 19 May 2006 - 03:12 AM

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!!

#2 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 19 May 2006 - 03:40 AM

[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]

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 May 2006 - 04:04 AM

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;


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 May 2006 - 08:34 AM

[!--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) View Post[/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].

#5 pcbguy

pcbguy
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 19 May 2006 - 02:28 PM

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.

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 May 2006 - 02:58 PM

If it register_globals is off then you use $_SERVER['PHP_SELF']

But if register_globals is on 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 <?=$_SERVER['PHP_SELF']?> I would chnage that to <?php echo $_SERVER['PHP_SELF']; ?> instead as not all servers are configured to use the <?= ?> tags.

#7 pcbguy

pcbguy
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 19 May 2006 - 03:10 PM

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.

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 May 2006 - 03:16 PM

also, it does not continue 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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 pcbguy

pcbguy
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 19 May 2006 - 03:46 PM

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?

#10 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 May 2006 - 03:48 PM

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\" /]
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 May 2006 - 05:28 PM

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.

#12 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 May 2006 - 09:03 PM

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\" /]


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#13 pcbguy

pcbguy
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 21 May 2006 - 11:00 PM

So if you were starting from scratch, and didn't know anything about programming at all. Where would start? What is the best "for dummies" tutorial you have found?

#14 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 11:26 PM

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\" /]


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#15 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 21 May 2006 - 11:34 PM

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

I got started using Jason Gilmore's PHP 5 and MySQL: From Novice to Professional, and once I learned the basics, I used the PHP manual.

http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#16 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 11:38 PM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users