Forum Moderators: coopster

Message Too Old, No Replies

Old script - newbie question

Keeping register globals off

         

riverstyx

7:56 pm on Jul 30, 2005 (gmt 0)

10+ Year Member



I have a script that I want to use but it wants register globals on -- I have it turned off and want to keep it off. I can't stay logged in as a user, obviously. Below is the login function -- what do I do to it in order to make it work for me? Declare the variables each time the function is called? Any input greatly appreciated:

function logincheck($uid, $upwd) {

if (($uid == "") ¦¦ ($upwd == "")) {
$accountok = false;
} else {
$sql = "select * from users where userid = $uid and password = '$upwd'";
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
if ($numrows > 0) {
$accountok = true;
} else
$accountok = false;
}
}
return $accountok;
}
--------------------
RS

dreamcatcher

8:06 pm on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi riverstyx,

If you are passing POST data via a form, you need to use the $_POST superglobal array. You can read up on them here:

[uk2.php.net...]

So, assuming your $upwd is coming from a form, you can use something like:

function logincheck($uid, $_POST['upwd'])

dc

riverstyx

8:11 pm on Jul 30, 2005 (gmt 0)

10+ Year Member



That's it?! Maybe I can do this afterall :)
Thank you...

RS

dreamcatcher

8:33 pm on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem. You should always try and write your code to assume that register globals are off anyway.

Good Luck.

dc

ergophobe

8:47 pm on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One thing that will help a lot if you haven't already done it is to set error_reporting to E_ALL in your php.ini file.

This will cause yo to receive a "Notice" whenever you try to use the value of an undefined variable. Since you have register_globals off, any variables that are coming from the form will be undefined and you'll get a notice.

aroul2k

11:21 pm on Jul 31, 2005 (gmt 0)

10+ Year Member



Hi, i'm new to php. I juz installed PHP5 to my web server. The problem is whenever i submitted a form to a php script, the script won't recognized the value unless i use superglobals variables instead e.g. $_POST, $_GET for every variables. I've downloaded fews scripts but it would be problem to change everything to superglobals variables. FYI, i've enable register_global in php.ini but it still doesn't work. Help me plz.

TQ

dreamcatcher

8:43 am on Aug 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi aroul2k,

When you changed the settings for 'register globals' did you re-start your Apache server? The changes won`t take affect until you re-start.

dc

aroul2k

8:23 pm on Aug 1, 2005 (gmt 0)

10+ Year Member



Hi dreamcatcher,

Thanks for that. Juz to check with you where does php.ini located?

in \etc\php.ini or \etc\php5\apache2\php.ini?
The one that I altered is in \etc\

Hope that u could help.

TQ

dreamcatcher

9:22 pm on Aug 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

If you create a script with the following code:

<?php

phpinfo();

?>

Save it as info.php, upload it then access it in your browser. Your PHP.ini location will be shown in the first block of information.

dc

aroul2k

12:48 am on Aug 2, 2005 (gmt 0)

10+ Year Member



Hi dreamcatcher,

thanks. if that's the case, it should be at /etc/php5/apache2/php.ini as shown at phpinfo();

any idea why old codes are not running on php5?

TQ

dreamcatcher

7:56 am on Aug 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP has register globals OFF by default since v2.0. Maybe you were running an earlier version originally?

dc