jamesxg1 Posted September 25, 2009 Share Posted September 25, 2009 I have this, <?php session_start(); class Login { private $username; private $password; private $salt = "pepper89378"; function SecureUsername($username) { $this->username = mysql_real_escape_string(trim(addslashes(strip_tags(base64_encode($username))))); return($this->username); } function SecurePassword($password, $salt) { $this->salt = sha1(md5($salt)); $this->password = mysql_real_escape_string(trim(addslashes(strip_tags(sha1(md5($password . $this->salt)))))); return($this->password); } function LoginSecure($this->username, $this->password) { $this->usernamecheck = "SELECT `username` FROM `members` WHERE username = '$this->username'"; $this->runusernamecheck = mysql_query($this->usernamecheck) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); if(mysql_num_rows($this->runusernamecheck) = 1) { $this->passwordcheck = "SELECT `password` FROM `members` WHERE username = '$this->username' AND password = '$this->password'"; $this->runpasswordcheck = mysql_query($this->passwordcheck) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); if(mysql_num_rows($this->runpasswordcheck) = 1) { $this->details = "SELECT * FROM `members` WHERE username = '$this->username' AND password = '$this->password'"; $this->rundetails = mysql_query($this->details) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); while($details = mysql_fecth_array($this->rundetails)) { $_SESSION['username'] = base64_decode($details['username']); $_SESSION['user_id'] = is_numeric($details['user_id']); if($details['ad'] = 1) { header('Location: suspended.php?username=' . base64_decode($details['username']) . '); } else { if($details['lf'] = 1) { header('Location: controlpanel.php?first=1'); } else { header('Location: controlpanel.php'); } } } } else { $this->wrongusername = "Wrong username, Please try again."; return($this->wrongusername); } } else { $this->wrongpassword = "Wrong password, Please try again."; return($this->wrongpassword); } } ?> I get this error, Fatal error: Cannot re-assign $this in C:\Program Files\xampp\xampp\htdocs\work\Login.inc.php on line 31 Line 31 = function LoginSecure($this->username, $this->password) { Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/175531-solved-how-do-i-use-a-functions-return-value-in-another-function/ Share on other sites More sharing options...
mikesta707 Posted September 25, 2009 Share Posted September 25, 2009 well, since you are assigning the data members already, you don't need to return anything with those functions. there are also a few syntax errors if(mysql_num_rows($this->runpasswordcheck) = 1) { should be if(mysql_num_rows($this->runpasswordcheck) == 1) { you want to use the comparison operator (==) not the assignment operator (=). you have to change that in a few places. Quote Link to comment https://forums.phpfreaks.com/topic/175531-solved-how-do-i-use-a-functions-return-value-in-another-function/#findComment-924947 Share on other sites More sharing options...
jamesxg1 Posted September 25, 2009 Author Share Posted September 25, 2009 , Changed. <?php session_start(); class Login { private $username; private $password; private $salt = "pepper89378"; function SecureUsername($username) { $this->username = mysql_real_escape_string(trim(addslashes(strip_tags(base64_encode($username))))); } function SecurePassword($password, $salt) { $this->salt = sha1(md5($salt)); $this->password = mysql_real_escape_string(trim(addslashes(strip_tags(sha1(md5($password . $this->salt)))))); } function LoginSecure($this->username, $this->password) { $this->usernamecheck = "SELECT `username` FROM `members` WHERE username = '$this->username'"; $this->runusernamecheck = mysql_query($this->usernamecheck) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); if(mysql_num_rows($this->runusernamecheck) == 1) { $this->passwordcheck = "SELECT `password` FROM `members` WHERE username = '$this->username' AND password = '$this->password'"; $this->runpasswordcheck = mysql_query($this->passwordcheck) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); if(mysql_num_rows($this->runpasswordcheck) == 1) { $this->details = "SELECT * FROM `members` WHERE username = '$this->username' AND password = '$this->password'"; $this->rundetails = mysql_query($this->details) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); while($details = mysql_fecth_array($this->rundetails)) { if($details['ad'] == 1) { header('Location: suspended.php?username=' . base64_decode($details['username']) . '); } else { $_SESSION['username'] = base64_decode($details['username']); $_SESSION['user_id'] = is_numeric($details['user_id']); $this->insert = "INSERT INTO `memberlogs` (`username`, `user_id`, `time`, `date`, `ip`, `browser`) VALUES('', '', '', '', '', '')"; $this->runinsert = mysql_query($this->insert) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); if($details['lf'] == 1) { header('Location: controlpanel.php?first=1'); } else { header('Location: controlpanel.php'); } } } } else { $this->wrongusername = "Wrong username, Please try again."; return($this->wrongusername); } } else { $this->wrongpassword = "Wrong password, Please try again."; return($this->wrongpassword); } } ?> I still have the same error :S. Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/175531-solved-how-do-i-use-a-functions-return-value-in-another-function/#findComment-924951 Share on other sites More sharing options...
mikesta707 Posted September 25, 2009 Share Posted September 25, 2009 Oh, i'm foolish. Didn't even read the line drawing the error. function LoginSecure($this->username, $this->password) { you can't pass data members as variables into methods. Why would you? you already have access to them since they are encapulated in the class. Make the function this function LoginSecure() and it should work as expected (assuming there are no more errors in the function) Quote Link to comment https://forums.phpfreaks.com/topic/175531-solved-how-do-i-use-a-functions-return-value-in-another-function/#findComment-924957 Share on other sites More sharing options...
jamesxg1 Posted September 25, 2009 Author Share Posted September 25, 2009 Lol. No as you can see you are the intelligent one here lol. I on the other hand am the foolish one lol. Cheers mate, Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/175531-solved-how-do-i-use-a-functions-return-value-in-another-function/#findComment-924961 Share on other sites More sharing options...
jamesxg1 Posted September 25, 2009 Author Share Posted September 25, 2009 Sorry to re-post again, But i get this error now, <?php session_start(); class Login { private $username; private $password; private $salt = "pepper89378"; function SecureUsername($username) { $this->username = mysql_real_escape_string(trim(addslashes(strip_tags(base64_encode($username))))); } function SecurePassword($password, $salt) { $this->salt = sha1(md5($salt)); $this->password = mysql_real_escape_string(trim(addslashes(strip_tags(sha1(md5($password . $this->salt)))))); } function LoginSecure() { $this->usernamecheck = "SELECT `username` FROM `members` WHERE username = '$this->username'"; $this->runusernamecheck = mysql_query($this->usernamecheck) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); if(mysql_num_rows($this->runusernamecheck) == 1) { $this->passwordcheck = "SELECT `password` FROM `members` WHERE username = '$this->username' AND password = '$this->password'"; $this->runpasswordcheck = mysql_query($this->passwordcheck) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); if(mysql_num_rows($this->runpasswordcheck) == 1) { $this->details = "SELECT * FROM `members` WHERE username = '$this->username' AND password = '$this->password'"; $this->rundetails = mysql_query($this->details) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); while($details = mysql_fecth_array($this->rundetails)) { $this->username = base64_decode($details['username']); $this->user_id = is_numeric($details['user_id']); if($details['ad'] == 1) { header('Location: suspended.php?username=' . $this->username . '); } else { $_SESSION['user_id'] = $this->user_id; $_SESSION['username'] = $this->username; $this->insert = "INSERT INTO `memberlogs` (`username`, `user_id`, `time`, `timea`, `date`, `ip`, `browser`) VALUES('$details['username']', '$details['user_id']', 'date('h:i')', 'date('A')', 'date("m-d-Y")', '', '')"; $this->runinsert = mysql_query($this->insert) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); if($details['lf'] == 1) { header('Location: controlpanel.php?first=1'); } else { header('Location: controlpanel.php'); } } } } else { $this->wrongusername = "Wrong username, Please try again."; return($this->wrongusername); } } else { $this->wrongpassword = "Wrong password, Please try again."; return($this->wrongpassword); } } ?> Parse error: syntax error, unexpected T_STRING in C:\Program Files\xampp\xampp\htdocs\socialbuild\Login.inc.php on line 58 Line 58: $_SESSION['user_id'] = $this->user_id; Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/175531-solved-how-do-i-use-a-functions-return-value-in-another-function/#findComment-924968 Share on other sites More sharing options...
TeNDoLLA Posted September 25, 2009 Share Posted September 25, 2009 Just a few lines above this <?php header('Location: suspended.php?username=' . $this->username . '); should be <?php header('Location: suspended.php?username=' . $this->username); If you look closely you will notice that the syntax highlighting in these forums also changes slightly after that line because of the single quote. You should get yourself some decent editor with syntax highlighting if you don't already have one. It makes a lot easier to spot errors/typos like this. Quote Link to comment https://forums.phpfreaks.com/topic/175531-solved-how-do-i-use-a-functions-return-value-in-another-function/#findComment-924971 Share on other sites More sharing options...
jamesxg1 Posted September 25, 2009 Author Share Posted September 25, 2009 Worked!, Cheers dude . Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/175531-solved-how-do-i-use-a-functions-return-value-in-another-function/#findComment-924972 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.