Getting started

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tally622
Forum Newbie
Posts: 4
Joined: Thu Dec 04, 2008 9:55 am

Getting started

Post by tally622 »

I am having a real problem with a tutorial I am trying to get thru. I am running this in Dreamweaver with WAMP and PHPMyAdmin on a Vista machine. I can't figure out why this single simple line of code is not working.

Code: Select all

<form name="dataEnter" id= "enterForm" method="post" action="index.php?function=add" >
In the URL (http://localhost/PHP_School/Connections ... nction=add) I can see that the function has been set but a simple if statement to print yes if function isset = add

Code: Select all

if(isset($function) && $function=="add")
or No if not keeps coming back "No". I have looked around but can't find a simple reason why this will not work. Is it my Dreamweaver or my WAMP settings or the fact that I am using Vista??? I have been working on this since yesterday and can get everything working but this simple function that is driving me crazy. I can't go any further without this. I know that you guys must cringe at some of the stupid this we ask, but I would really appreciate some help.
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: Getting started

Post by Reviresco »

You may need to add this:

Code: Select all

$function = $_GET['function'];
tally622
Forum Newbie
Posts: 4
Joined: Thu Dec 04, 2008 9:55 am

Re: Getting started

Post by tally622 »

Copy and Pasted and it worked! Now the question is, how can I sit here and watch the video tutorial and it works just fine without this line of code? I hate to just blindly accept this fix without knowing why the author would just leave this out, and apparently doesn't need it. Seriously, thanks a bunch, I can continue now but anyone with an idea as to why this works/not works would be appreciated. Thanks again.
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: Getting started

Post by Reviresco »

It's a setting in your php installation called register_globals. If it's set to on, there's automatically a variable called $whatever for any $_GET['whatever'] variable in a URL such as:

http://www.example.com?whatever=something.

If register_globals is off, you have to set the variable as in the above posts:

$whatever = $_GET['whatever'];

(You don't have to name it $whatever, it could be $anything_else.)

In PHP 4.2.0 and later, the default value for the PHP directive register_globals is off.
tally622
Forum Newbie
Posts: 4
Joined: Thu Dec 04, 2008 9:55 am

Re: Getting started

Post by tally622 »

Yes, thanks, that makes a lot of sense. If default is "off" is that the standard setting that most people use? Is this a security issue?
guygk
Forum Newbie
Posts: 9
Joined: Thu Dec 04, 2008 4:06 pm

Re: Getting started

Post by guygk »

Yes it is for security reasons.
But if you set all your in risk factor variables to default meaning (ex. NULL) at the begging of the code there is no risk to use register_globals. In some cases it might be event helpful.
tally622
Forum Newbie
Posts: 4
Joined: Thu Dec 04, 2008 9:55 am

Re: Getting started

Post by tally622 »

From php.ini ...

; You should do your best to write your scripts so that they do not require
; register_globals to be on; Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.

My word, how could you possibly suggest that!! Do you want your code to be not very well thought of?

Yeah, I've had a chance to look into this a little bit since it was pointed out to me. Looks like this move by PHP has critics and defenders. I really appreciate the help and follow up comments.
Post Reply