Jump to content

Adding data...


2old2learn?

Recommended Posts

you can find for eregi() in line 75 and replace with preg_match(). eregi() is deprecated function. they discourage to use it anymore.You get the same hash because you had used the same password for that two username.
Ahhh okay duplicate password duplicates the hash ...thanks..for info...and the eregi() like this :
if(empty($this->email) || !preg_match(('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email))

or should be like this

if(empty($this->email) || !preg_match()('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email)

Edited:This is the line error I get now...

$this->token	= $_POST['token'];

log in message is :

Notice: Undefined index: token in C:\xampp\htdocs\login_scripts\class.login.php on line 20Members Area
Link to comment
Share on other sites

  • Replies 251
  • Created
  • Last Reply

this one is correct.

if(empty($this->email) || !preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/',$this->email))

preg_match() will take two parameter string the first param will take reguler expression pattern and second one will take the content which will have to check. http://php.net/function.preg_match

Notice: Undefined index: token in C:\xampp\htdocs\login_scripts\class.login.php on line 20Members Area
every time you will create a object it will throw this notice if the $_POST['token'] is empty. when it reiderct to index.php it dont have any $_POST data so when you create the object of login class at this point $this->token = $_POST['token']; error has been thrown.
Link to comment
Share on other sites

this one is correct.
if(empty($this->email) || !preg_match('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email))

preg_match() will take two parameter string the first param will take reguler expression pattern and second one will take the content which will have to check. http://php.net/function.preg_matchevery time you will create a object it will throw this notice if the $_POST['token'] is empty. when it reiderct to index.php it dont have any $_POST data so when you create the object of login class at this point $this->token = $_POST['token']; error has been thrown.

Hmmm???Here is the index.php code don't fully understand what actions it is doing..
<?phpsession_start();include('/class.login.php');$login = new Login();if($login->isLoggedIn())  echo "Members Area";   else  echo "Front Page";?>

Link to comment
Share on other sites

$login = new Login();
when you create a instance of a class the constructor is implictly be invoked. so if you look into the __construct() constructor you will see that it is initializing values. the property 'token' is being initialized by $_POST['token'].But is there were any post data? no,there was not any post data was passed to index.php. so $_POST['token'] will be unitialized.and it is assgihng the value of a variable which does not exist.So thats the reason it is showing the erros.
public function __construct() { $this->_errors = array(); $this->_login = isset($_POST['login'])? 1 : 0; $this->_access = 0; $this->_token = $_POST['token']; <<< First error message $this->_id = 0; $this->_username = ($this->_login)? $this->filter($_POST['username']) : $_SESSION['username']; <<<Second error message $this->_password = ($this->_login)? $this->filter($_POST['password']) : ''; $this->_passmd5 = ($this->_login)? md5($this->_password) : $_SESSION['password']; <<< Third error message.. }
You can change that something like this to prevent the notice like this $this->token=isset($_POST['token'])?$_POST['token]:'';
Link to comment
Share on other sites

when you create a instance of a class the constructor is implictly be invoked. so if you look into the __construct() constructor you will see that it is initializing values. the property 'token' is being initialized by $_POST['token'].But is there were any post data? no,there was not any post data was passed to index.php. so $_POST['token'] will be unitialized.and it is assgihng the value of a variable which does not exist.So thats the reason it is showing the erros.You can change that something like this to prevent the notice like this $this->token=isset($_POST['token'])?$_POST['token]:'';
Okay I've added the new line $this->token=isset($_POST['token']) ? $_POST['token']:''; Same result occurred..Edited:You say;
But is there were any post data? no,there was not any post data was passed to index.php.
I am correct you are saying that something after $_POST something has to be returned to index.php???
Link to comment
Share on other sites

Okay I've added the new line $this->token=isset($_POST['token']) ? $_POST['token']:'';
did you add a new one or replaced previous one ? you have to replace that here
public function __construct(){$this->_errors = array();$this->_login = isset($_POST['login'])? 1 : 0;$this->_access = 0;$this->_token=$_POST['token']			  //<============$this->token=isset($_POST['token']) ? $_POST['token']:'';

Link to comment
Share on other sites

did you add a new one or replaced previous one ? you have to replace that here
public function __construct(){$this->_errors = array();$this->_login = isset($_POST['login'])? 1 : 0;$this->_access = 0;$this->_token=$_POST['token']			  //<============$this->token=isset($_POST['token']) ? $_POST['token']:'';

OOOOps! Sorry missed understood the action you were meaning will redo it again...my bad...Edited:This is the way it looks now!
public function __construct()  {	$this->errors = array();	$this->username = $this->filter($_POST['ruser']);	$this->password = $this->filter($_POST['rpass']);	$this->email	= $this->filter($_POST['remail']);	$this->token	= isset($_POST['token']) ? $_POST['token']:'';

is this right

Link to comment
Share on other sites

I am correct you are saying that something after $_POST something has to be returned to index.php???
according to the code, yes it wants some $_POST['token'] in the script. So that we change the script to$this->token=isset($_POST['token']) ? $_POST['token']:''; so if the $_POST['token'] does not exist it will assign the $this->token with empty string an else assighn the value of $_POST'token']. so now its now quite indipendent to $POST['token'] has set or not.Though notice is a lower level of error. your script will still work fine as you have already seen. but its annoying to see the notices and its better to fix where it is possible.
Link to comment
Share on other sites

according to the code, yes it wants some $_POST['token'] in the script. So that we change the script to$this->token=isset($_POST['token']) ? $_POST['token']:''; so if the $_POST['token'] does not exist it will assign the $this->token with empty string an else assighn the value of $_POST'token']. so now its now quite indipendent to $POST['token'] has set or not.Though notice is a lower level of error. your script will still work fine as you have already seen. but its annoying to see the notices and its better to fix where it is possible.
Okay..cool The correction you gave still give same error message...hoping to get a hold of script editor and explain to him what error message I am getting...Okay just posted a comment on the editor's channel at youtube:Comment Posted:
Hey I've downloaded both your scripts of login also the register login..I integrated the register.login.php with a link in the login.php ....but I get this error on the index.php page>>>>This is the error message>>>>" Notice: Undefined index: token in C:\xampp\htdocs\login_scripts\­class.login.php on line 20Members Area "
Link to comment
Share on other sites

still getting same error? can you show the corrected code?

Link to comment
Share on other sites

still getting same error? can you show the corrected code?
Posted above but here is the corrected code again:
public function __construct()  {	$this->errors = array();	$this->username = $this->filter($_POST['ruser']);	$this->password = $this->filter($_POST['rpass']);	$this->email	= $this->filter($_POST['remail']);	$this->token	= isset($_POST['token']) ? $_POST['token']:'';

Link to comment
Share on other sites

are you sure it is the notice for 'token'? you have changed the code of username,password,email assighnment as i can see from your post. i guess that is one of them raising error now not the 'token'

Link to comment
Share on other sites

are you sure it is the notice for 'token'? you have changed the code of username,password,email assighnment as i can see from your post. i guess that is one of them raising error now not the 'token'
Still getting same error message:
Notice: Undefined index: token in C:\xampp\htdocs\login_scripts\class.login.php on line 20Members Area
Well there is two scripts..1: Login.php2: Register.phpIn the login.php I've added a re-direct link to register.php if not a member already..this works a new user is added..What I have done though is delete two of the users and left the current one for testing..Login Script:
<?phpsession_start();if(isset($_POST['login'])){  include('/class.login.php');  $login = new Login();  if($login->isLoggedIn())	 header('location: index.php');  else	$login->showErrors();}$token = $_SESSION['token'] = md5(uniqid(mt_rand(),true));?><form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>"><table> <tr><td>Username:</td><td><input type="text" name="username" /></td></tr> <tr><td>Password:</td><td><input type="password" name="password" /></td></tr></table><input type="hidden" name="token" value="<?php echo $token;?>" /><input type="submit" name="login" value="Log In" /><br><a href="http://localhost/login_scripts/register.php">Register</a></form>

register script:

<?phpsession_start();if(isset($_POST['register'])){  include_once('/class.register.php');  $register = new Register();  if($register->process())	echo "Successfully Signed Up!";  else	$register->show_errors();}$token = $_SESSION['token'] = md5(uniqid(mt_rand(),true));?><form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>"> <table>  <tr><td>Username:</td><td><input type="text" name="ruser"/></td></tr>  <tr><td>Password:</td><td><input type="password" name="rpass"/></td></tr>  <tr><td>Email:</td><td><input type="text" name="remail"/></td></tr> </table> <input type="hidden" name="token" value="<?php echo $token;?>"/> <input type="submit" name="register" value="Sign Up"/></form>

Link to comment
Share on other sites

:) wait a minute you are editing the register class. you have to edit the login class! :)
Link to comment
Share on other sites

:) wait a minute you are editing the register class. you have to edit the login class! :)
Damn ... sorry mate I see what you mean...will make the change now...silly me...Edited:Okay success..just says "Member's Area" okay now I guess I need a logout added to this page..????Okay now cleaned out cookies..thru internet options..and now I get this error..
Notice: Undefined index: username in C:\xampp\htdocs\login_scripts\class.login.php on line 23Notice: Undefined index: password in C:\xampp\htdocs\login_scripts\class.login.php on line 25Front Page
here is where the error are stated: in the "class.login.php" page.
public function __construct()  {	$this->_errors = array();	$this->_login  = isset($_POST['login'])? 1 : 0;	$this->_access = 0;	$this->token   = isset($_POST['token']) ? $_POST['token']:'';  <<-- First Error message	$this->_id	   = 0;	$this->_username = ($this->_login)? $this->filter($_POST['username']) : $_SESSION['username'];	$this->_password = ($this->_login)? $this->filter($_POST['password']) : '';	$this->_passmd5  = ($this->_login)? md5($this->_password) : $_SESSION['password']; <<--Second Error message  }

Okay I've deleted all users from database..and now get this in the class.register.php file..

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\xampp\htdocs\login_scripts\class.register.php on line 76
Here is the line 76 code:
if(empty($this->email) || !preg_match('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email))	  $this->errors[] = 'Invalid Email';

not sure but I think I found the error I didn't have an email field...testing it now..edited...still same error...even with field " email " added..

Link to comment
Share on other sites

Okay Okay..I know I am bit of a fool..but I do think I do make some headway..previous post got the error..but I just noticed..and error..so made a change in class.register.phpre-added this line to class.register.php and got a successful login..but still a Deprecated error which I don't understand ...what does " Deprecated " mean???

if(empty($this->email) || !eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email))	  $this->errors[] = 'Invalid Email';

This is the line of error now..

Deprecated: Function eregi() is deprecated in C:\xampp\htdocs\login_scripts\class.register.php on line 76Successfully Signed Up!
Sorry guys for my foolish mistakes...Edited:Okay checked database a new user was added..but no email address was added in the email " field ";
Link to comment
Share on other sites

Hey...for some reason it won't add the email address I've added..I am gonna delete the users table and start the table from scratch again..email during register is not being added..Damn okay this is starting to drive me nuts...need a break...

Link to comment
Share on other sites

A recap..is this right code string this comes from the class.register.php file..

if(empty($this->email) || !preg_match(/'^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$'/,$this->email))

got correction on code string should be like thisThis is the correct string..

if(empty($this->email) || !preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/',$this->email))

I am still attempting to get this..piece by piece..if I have to..LOL... :)Okay with adding the corrected string..I now get a " Successfully Signed Up!" message without any other error message page is clean..

Link to comment
Share on other sites

Okay have fixed some error's but still get " Invalid Form Submission " in the login.php while trying to login...but here is what was fixed in the class.login.php file

	$this->_id	   = 0;	$this->_username = ($this->_login)? $this->filter($_POST['username']) : (isset($_SESSION['username']) ? $_SESSION['username']: null);	$this->_password = ($this->_login)? $this->filter($_POST['password']) : (isset($_SESSION['password']) ? $_SESSION['password']: null);	$this->_passmd5  = ($this->_login)? md5($this->_password) : (isset($_SESSION['password']) ? $_SESSION['password'] : null);

now when I go to the index.php I get the words " Front Page " only showing up now..

Link to comment
Share on other sites

still get " Invalid Form Submission " in the login.php while trying to login...
the reason for the error is same as same as here
$this->_id = 0; $this->_username = ($this->_login)? $this->filter($_POST['username']) : (isset($_SESSION['username']) ? $_SESSION['username']: null); $this->_password = ($this->_login)? $this->filter($_POST['password']) : (isset($_SESSION['password']) ? $_SESSION['password']: null); $this->_passmd5 = ($this->_login)? md5($this->_password) : (isset($_SESSION['password']) ? $_SESSION['password'] : null);
i am not sure. i cant see the token property in your post. is that there or you had removed already? i thought your login script is working already.
Link to comment
Share on other sites

the reason for the error is same as same as here i am not sure. i cant see the token property in your post. is that there or you had removed already? i thought your login script is working already.
yea those lines of code now clear up any errors..now on index page just see the words " Front Page "....and i believe this shows when not logged in..cause checking code if logged in it will show " Members area "
Link to comment
Share on other sites

okay did this to check things

public function __construct()    {		$this->_errors = array();	$this->_login  = isset($_POST['login'])? 1 : 0;	$this->_access = 0;	$this->token   = isset($_POST['token'])? $_POST['token']:'';	var_dump('$_POST');	$this->_id	   = 0;	$this->_username = ($this->_login)? $this->filter($_POST['username']) : (isset($_SESSION['username']) ? $_SESSION['username']: null); //wow that's long	$this->_password = ($this->_login)? $this->filter($_POST['password']) : (isset($_SESSION['password']) ? $_SESSION['password']: null);	$this->_passmd5  = ($this->_login)? md5($this->_password) : (isset($_SESSION['password']) ? $_SESSION['password'] : null);  }

Once logging in got the error message " string(6) "$_POST" ErrorsInvalid Form Submission
And when I do a var_dump('$_SESSION'); I get
string(9) "$_SESSION" ErrorsInvalid Form Submission
Okay... :)
Link to comment
Share on other sites

you are using var_dump('$_POST'); when you use it in single quote it will be treated as string not as variable or array So the var dump just showing it as it is

string(6) "$_POST"
if you look into the digit (eg, 6) in bracet it is just length of the string. whn you var dump some array it will be shown as something like
array(1) { ["a"]=> string(1) "3" }

same with $_SESSION also.check the var_dump() of $_SESSION that 'token' does exist or no at the time of login form submit.

Link to comment
Share on other sites

you are using var_dump('$_POST'); when you use it in single quote it will be treated as string not as variable or array So the var dump just showing it as it is if you look into the digit (eg, 6) in bracet it is just length of the string. whn you var dump some array it will be shown as something like
array(1) { ["a"]=> string(1) "3" }

same with $_SESSION also.check the var_dump() of $_SESSION that 'token' does exist or no at the time of login form submit.

So my var_dump("$_POST"); <<< like then ??? same as $_SESSION
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...