Ok..can someone PLEASe explain how the Globals thing works in PHP! In Perl you can define a variable as a variable, and it is automatically defined as a global...unless you give it a 'my' or 'local' value. So, comming from a Perl background this is really confusing me
I'm using the following code;
Basically, what I was trying to do is get the authentication thing to work. To start with I just want to print out the $rate_code thing as a variable and print it in login(). However, everything is getting printed EXCEPT the $rate_code! Anyone wanna offer some help?
Thanks
Andy
I'm using the following code;
Code:
<?php
// VARIABLES TO SET UP!
// Admin password...for editing the users and adding new ones.
$admin_password = "password";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
$action = $_action;
$password = $_password;
$crypt_password = crypt($admin_password, 'MM');
$crypt_submit_password = crypt($_submit_admin_password, 'MM');
$new_username_add = $_new_username;
$new_password_add = $_new_password;
$path = $
global $action, $action, $password, $crypt_password, $crypt_submit_password, $new_username_add, $new_password_add;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
load_codes();
decide(); // now we decide what to do
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function decide() {
global $action, $action, $password, $crypt_password, $crypt_submit_password, $rate_code, $new_username_add, $new_password_add;
if ($action == "") { login_page(); exit;}
elseif ($action == "login") { login(); exit; }
else { login_page(); exit;}
} // end the decide function
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function login_page() {
// deifne the globals
global $action, $action, $password, $crypt_password, $crypt_submit_password, $rate_code, $new_username_add, $new_password_add;
echo "logging in page";
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function login() {
// globalise the main things
global $action, $action, $password, $crypt_password, $crypt_submit_password, $rate_code, $new_username_add, $new_password_add;
echo "logging in page after submit $rate_code";
echo $GLOBALS;
echo $rate_code;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
// load up improtant codes..like the rate codes...
function load_codes() {
$rate_code = "rate code";
global $rate_code;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
// error sub...in case something goes wrong!
function error($error) {
echo "There was an error. It was;<BR><BR>";
echo $error;
exit;
} //end the error sub
?>
Basically, what I was trying to do is get the authentication thing to work. To start with I just want to print out the $rate_code thing as a variable and print it in login(). However, everything is getting printed EXCEPT the $rate_code! Anyone wanna offer some help?
Thanks
Andy