/    Sign up×
Community /Pin to ProfileBookmark

Installing PHP? Confused…

Hell all!, I’m an absolute newbie to PHP and backend scripting in general. I would like to learn the language on a local environment, so i installed IIS on win xp and downloaded php from php.net. So after all that I started to crack my tuturial and start learning, but now i notice that when I view my php files in a browser, i get the notice of undefined errors. I’m guessing that has to do with register_global?? My real question is, do PHP coders, who work locally deal with the crappy output that occurs with register_global off? or do they switch it on? And if they do switch it on…how?!? Or do they simply test on a rental host server? Thanks in advance!

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 29.2005 — The problem is that orginally PHP tended to be installed with register_globals turned on. Then it was realized that this can result in some undesirable things happening, both from a coding aspect and a security aspect. So now the default installation (and I would say the recommended installation) is to have register_globals turned off. Unfortunately, if you work with older scripts or scripts distributed by those today who don't realize the problem this causes, it can be annoying.

But if in all your scripts you always refer to GET and POST inputs via the $_GET and $_POST arrays, then it does not matter whether the particular installation you run it on has register_globals turned on or off. I realize that doesn't make life any easier dealing with legacy scripts, but at least it will prevent you from passing the disease on to others. ?
Copy linkTweet thisAlerts:
@NoAssmblyReqdauthorOct 29.2005 — what do you mean "in all my scripts refer to get and post inputs via.."? Thanks though for your reply
Copy linkTweet thisAlerts:
@NogDogOct 29.2005 — When a form submits data via the post method, the values from the form fields are stored in an array called $_POST, with the array keys being the names of the form elements. So if you have a form with input elements named "one", "two", and "three"; when submitted to a PHP script their values are accessible as $_POST['one'], $_POST['two'], and $_POST['three']. If register_globals is turned on, they are also accessible as $one, $two, and $three. So my point is, the $_POST['name'] variable is there regardless of the register_globals setting, so you can always count on it working. The $name alternative only works if register_globals is turned on, so it cannot be depended upon to work in any installation. So, for maximum portability of your scripts you should always assume that register_globals will be turned off, and you should therefore always reference the post data via the $_POST array (or get data via the $_GET array).
Copy linkTweet thisAlerts:
@rorycanyonOct 29.2005 — I think you are using an old tutorial, why not change your tutorial since it's now a little bit out of time? Buy sth targetted at PHP5.
Copy linkTweet thisAlerts:
@NoAssmblyReqdauthorOct 29.2005 — how do u turn register_globals on? and what do they mean, it poses a security. How would that apply to my desktop pc and iis?
Copy linkTweet thisAlerts:
@chazzyOct 29.2005 — You don't want to turn them on. They make your code confusing - $_GET variables change their names. same with everything in the global arrays. CAn you show us what part of your code is giving you undefined errors? The problem is not a change in PHP settings - they work fine out of the box, the problem's most likely in scripting.
Copy linkTweet thisAlerts:
@NogDogOct 29.2005 — how do u turn register_globals on? and what do they mean, it poses a security. How would that apply to my desktop pc and iis?[/QUOTE]
http://www.php.net/manual/en/security.globals.php
Copy linkTweet thisAlerts:
@NoAssmblyReqdauthorOct 29.2005 — i get a variable error with the following: <?php echo $PHP_SELF ?>

granted, im on the 4th page in this book...lol

oh, and yea, this book seems old. I believe it was written around the time of version 3. but it was free, so i figured i'd learn the fundamentals with it, then catch up with resources on the net. with that simple script im getting errors, or "notices" which is making it afraid to continue the lessons.

If i turn (in php.ini ) to not so strict, i dont get a notice, but rather blank output all together! someone please help. thanks again
Copy linkTweet thisAlerts:
@jabezOct 29.2005 — You really are doing your (PHP?)self a great injustice by trying to learn the latest version of PHP with an old tutorial book like you mention.

You need to get an up to date tutorial on PHP4/5 - PHP3 is as dead as a dodo now, and so is alot of the php 3 syntax.

One of the main differences between PHP4 and PHP5 is the new object model in PHP5. Most PHP4 code should run under PHP5, with few modifications. There is a new exception syntax as well for error handling, but this is optional.

Copy this script and run it. You will see that $PHP_SELF has changed syntax. It now lives in the $_SERVER[] associative array, which is probably why you were getting an undefined variable error/warning.

<?php

// output all of the $_SERVER array

echo "<br />contents of $_
SERVER[] <br />";

while(list($key, $value) = each($_SERVER))

{

echo "$key => $value <br />";

}

// this will produce no output, or a warning message - undefined variable!

echo "<br /> contents of $PHP_SELF <br />";

echo $PHP_SELF;

// correct syntax to access PHP_SELF

echo "<br /> contents of $_SERVER['PHP_SELF'] <br />";

echo $_
SERVER['PHP_SELF'];

?>

HTH :-)
×

Success!

Help @NoAssmblyReqd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...