Jump to content

Adding data...


2old2learn?

Recommended Posts

the error means what it says there is no such function. i think you are probably looking for mt_rand()

Link to comment
Share on other sites

  • Replies 251
  • Created
  • Last Reply
the error means what it says there is no such function. i think you are probably looking for mt_rand()
mt_rand() oh I thought it was nt_rand() okay will check..
Link to comment
Share on other sites

mt_rand() oh I thought it was nt_rand() okay will check..
Okay now works..missed something also..It also created the md5 hash..thanks..
Link to comment
Share on other sites

Okay now working with a login script thru a tutorial from youtube..downloaded his script..and I get the following errors...Notice: Undefined index: token in C:\xampp\htdocs\login_scripts\class.login.php on line 20Notice: 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 PageHere is the class.login.php script: Now this is an advanced version of many login script tutorials..on youtube..maybe should work with the easy one's first before getting into this one...

<?phpclass Login{  private $_id;  private $_username;  private $_password;  private $_passmd5;  private $_errors;  private $_access;  private $_login;  private $_token;  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..  }  public function isLoggedIn()  {	($this->_login)? $this->verifyPost() : $this->verifySession();	return $this->_access;  }  public function filter($var)  {	return preg_replace('/[^a-zA-Z0-9]/','',$var);  }  public function verifyPost()  {	try	{	  if(!$this->isTokenValid())		 throw new Exception('Invalid Form Submission');	  if(!$this->isDataValid())		 throw new Exception('Invalid Form Data');	  if(!$this->verifyDatabase())		 throw new Exception('Invalid Username/Password');	$this->_access = 1;	$this->registerSession();	}	catch(Exception $e)	{	  $this->_errors[] = $e->getMessage();	}  }  public function verifySession()  {	if($this->sessionExist() && $this->verifyDatabase())	   $this->_access = 1;  }  public function verifyDatabase()  {	//Database Connection Data	mysql_connect("localhost", "root", "") or die(mysql_error());	mysql_select_db("tecicc") or die(mysql_error());	$data = mysql_query("SELECT ID FROM user WHERE username = '{$this->_username}' AND password = '{$this->_passmd5}'");	if(mysql_num_rows($data))	  {		list($this->_id) = @array_values(mysql_fetch_assoc($data));		return true;	  }	else	  { return false; }  }  public function isDataValid()  {	return (preg_match('/^[a-zA-Z0-9]{5,12}$/',$this->_username) && preg_match('/^[a-zA-Z0-9]{5,12}$/',$this->_password))? 1 : 0;  }  public function isTokenValid()  {	return (!isset($_SESSION['token']) || $this->_token != $_SESSION['token'])? 0 : 1;  }  public function registerSession()  {	$_SESSION['ID'] = $this->_id;	$_SESSION['username'] = $this->_username;	$_SESSION['password'] = $this->_passmd5;  }  public function sessionExist()  {	return (isset($_SESSION['username']) && isset($_SESSION['password']))? 1 : 0;  }  public function showErrors()  {	echo "<h3>Errors</h3>";	foreach($this->_errors as $key=>$value)	  echo $value."<br>";  }}?>

And wondering how to impliment this into my project...

Link to comment
Share on other sites

Okay slowly working this out..created a table " users " added user and password to it..so I signed in and got just this error only..on line 76..Error message: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\login_scripts\class.login.php on line 76here is line 76

if(mysql_num_rows($data))<<< full script is previous post<<<<<

Thanks..Here is the youtube video link I got this from....

Link to comment
Share on other sites

do you know about implemention of object oriented programing in php? if you had not checked it yet i think you should first check the basic oop before getting into in it. http://php.net/language.oop5

Error message: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\login_scripts\class.login.php on line 76
this error means that your mysql_query is returning false which means your query is failing. why it is failing if you want to know you have to check the mysql_error()
Link to comment
Share on other sites

do you know about implemention of object oriented programing in php? if you had not checked it yet i think you should first check the basic oop before getting into in it. http://php.net.language.oop5 this error means that your mysql_query is returning false which means your query is failing. why it is failing if you want to know you have to check the mysql_error()
Dead link?Doesn't go anywhere
Link to comment
Share on other sites

do you know about implemention of object oriented programing in php? if you had not checked it yet i think you should first check the basic oop before getting into in it. http://php.net.language.oop5 this error means that your mysql_query is returning false which means your query is failing. why it is failing if you want to know you have to check the mysql_error()
Okay I think I found a small portion of the error..here was the code before with you help..I found
$data = mysql_query("SELECT ID FROM user WHERE username = '{$this->_username}' AND password = '{$this->_passmd5}'");

Was " user " now changed to "users" so now shows

$data = mysql_query("SELECT ID FROM users WHERE username = '{$this->_username}' AND password = '{$this->_passmd5}'");

now just says "Errors " and invalid username/password

Link to comment
Share on other sites

sorry! i fixed it.

Link to comment
Share on other sites

now just says "Errors " and invalid username/password
does your table holds any information about user and hashed password? are you using any sign up script?
Link to comment
Share on other sites

does your table holds any information about user and hashed password? are you using any sign up script?
Yes I have a username and password entered into the table..and using the login form..In my table I have 3 fields..id, username, password...should I have another for hash pass
Link to comment
Share on other sites

here is the login form;

<?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" /></form>

Link to comment
Share on other sites

Yes I have a username and password entered into the table..and using the login form..
login form does not isert data about user. you need to make a sign up from first to insert the information then you need to use the login script which will check the username and password combo against the information stored in the database.how do you login a user who does not exist? do you have any sign up form?
In my table I have 3 fields..id, username, password...should I have another for hash pass
you dont need to create another column for hash pass. md5() which you had used is hash function which hash your password.
Link to comment
Share on other sites

login form does not isert data about user. you need to make a sign up from first to insert the information then you need to use the login script which will check the username and password combo against the information stored in the database.how do you login a user who does not exist? do you have any sign up form?
Well I manually added user and password thru phpMySQL ..into the users table fields...I see this in phpMySQL for users table...: Showing rows 0 - 0 (~11 total, Query took 0.0013 sec)SELECT * FROM `users` LIMIT 0 , 301 row is entered here it is showing id username password 1 admin admin1
Link to comment
Share on other sites

manually inserted password and the hashed password will not match.

$this->_passmd5 = ($this->_login)? md5($this->_password) : $_SESSION['password'];
this line will hash your password at this point. to match the password correctly you need to be stored the password hashed.if you manualy store it, it will be stored as plain text password.md5() will return a 32 character long alphanumeric string for a partiuclar string which had passed in it as parameter.echo md5('sometext'); // will not return sometext itself.it will return a 32 char hashed string. the link in above post will lead to you the manual page of it.
Link to comment
Share on other sites

manually inserted password and the hashed password will not match.this line will hash your password at this point. to match the password correctly you need to be stored the password hashed.if you manualy store it, it will be stored as plain text password.md5() will return a 32 character long alphanumeric string for a partiuclar string which had passed in it as parameter.echo md5('sometext'); // will not return sometext itself.it will return a 32 char hashed string. the link in above post will lead to you the manual page of it.
ahhh okay so your saying the link you gave will show manual on the md5 hash??
Link to comment
Share on other sites

yes, i mean that will show you the information about md5().it will be good if you a set up signup script. it will not be much long to set up. if you are unwilling to do so for now you can put the the 'e00cf25ad42683b3df678c61f42c6bda' in the password column 'admin1' and test for now the login script'e00cf25ad42683b3df678c61f42c6bda' that string is the print of md5('admin1')

echo md5('admin1');

Link to comment
Share on other sites

yes, i mean that will show you the information about md5().it will be good if you a set up signup script. it will not be much long to set up. if you are unwilling to do so for now you can put the the 'e00cf25ad42683b3df678c61f42c6bda' in the password column 'admin1' and test for now the login script'e00cf25ad42683b3df678c61f42c6bda' that string is the print of md5('admin1')
echo md5('admin1');

Okay for now I will just copy and paste..strange on the tutorial didn't give a registration setup..hmmmm...but will have to re-check it out..Well I added the hash in the password column didn't do a thing other than say invalid form dataWell taking a break will do a registration form..later...after hockey playoff game..
Link to comment
Share on other sites

invalid form submission error message is caused by another function not that function which was checking the database.

public function verifyPost() { try { if(!$this->isTokenValid()) throw new Exception('Invalid Form Submission');
this is the origin of the error. now you have to check why it is entering to throw the exception? cause istokenvalid() function is returning false. why that function is returning false? now check that function
public function isTokenValid() { return (!isset($_SESSION['token']) || $this->_token != $_SESSION['token'])? 0 : 1; }
that function will return false(0 is considered as false if its being compared loosely) when $_SESSION['token'] is not being set or the $this->token is not equal to $_SESSION['token'] so there cpuld be two reason for retruning false. either the session has expired or the the $this->token which is not the same as the token is session.$this->token is nothing but the token passed with your login form
$this->_token = $_POST['token'];
from this the $_POST['token'] is coming
<input type="hidden" name="token" value="<?php echo $token;?>" />
Link to comment
Share on other sites

invalid form submission error message is caused by another function not that function which was checking the database. this is the origin of the error. now you have to check why it is entering to throw the exception? cause istokenvalid() function is returning false. why that function is returning false? now check that functionthat function will return false(0 is considered as false if its being compared loosely) when $_SESSION['token'] is not being set or the $this->token is not equal to $_SESSION['token'] so there cpuld be two reason for retruning false. either the session has expired or the the $this->token which is not the same as the token is session.$this->token is nothing but the token passed with your login formfrom this the $_POST['token'] is coming
Oh sorry just realized also this is just for work only...no need for anyone to register..so a registery form needed..limited users would be manually inputted..I will post a comment to the guy who did the video tutorial at youtube..bout the error's..and see what comes of it..
Link to comment
Share on other sites

i think if you hard reload the page and try again it should work.probably the session has expired for inactivity of certain amount of time. i think you are so close.

Link to comment
Share on other sites

i think if you hard reload the page and try again it should work.probably the session has expired for inactivity of certain amount of time. i think you are so close.
Hey thanks for the encouragement..I also just sent a message to the script editor..of the problems..Again thanks..also will a reload of page as you suggest...fingers crossed...lol
Link to comment
Share on other sites

To continue the login session..I have found that the person who made the video tutorial has a register setup also..I've added it..but these errors occur..Index.php I get these errors..

Notice: Undefined index: token in C:\xampp\htdocs\login_scripts\class.login.php on line 20Notice: 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
This is index.php code:
<?phpsession_start();include('/class.login.php');$login = new Login();if($login->isLoggedIn())  echo "Members Area";else  echo "Front Page";?>

I've added the following line to the login code:

<a href="http://localhost/login_scripts/register.php">Register</a>

To re-direct user to registration form..but get this error ...but new user is added I've checked the database and user is added????

Deprecated: Function eregi() is deprecated in C:\xampp\htdocs\login_scripts\class.register.php on line 75Successfully Signed Up!
Here is registration code:
<?phpclass Register{  private $username;  private $password;  private $passmd5;  private $email;  private $errors;  private $token;  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	= $_POST['token'];	$this->passmd5  = md5($this->password);  }  public function process()	<<<---This is line 25 where it says error occurs..!!!!  {	if($this->valid_token() && $this->valid_data())		 $this->register();	return count($this->errors)? 0 : 1;  }  public function filter($var)  {	return preg_replace('/[^a-zA-Z0-9@.]/','',$var);  }  public function register()  {   mysql_connect("localhost","root","") or die(mysql_error());   mysql_select_db("tecicc") or die (mysql_error());   mysql_query("INSERT INTO users(username,password) VALUES ('{$this->username}','{$this->passmd5}')");   if(mysql_affected_rows()< 1)	 $this->errors[] = 'Could Not Process Form';  }  public function user_exists()  {	mysql_connect("localhost","root","") or die(mysql_error());	mysql_select_db("tecicc") or die (mysql_error());	$data = mysql_query("SELECT ID FROM users WHERE username = '{$this->username}'");	return mysql_num_rows($data)? 1 : 0;  }  public function show_errors()  {	echo "<h3>Errors</h3>";	foreach($this->errors as $key=>$value)	  echo $value."<br>";  }  public function valid_data()  {	if($this->user_exists())	  $this->errors[] = 'Username Already Taken';	if(empty($this->username))	  $this->errors[] = 'Invalid Username';	if(empty($this->password))	  $this->errors[] = 'Invalid Password';	if(empty($this->email) || !eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email))	  $this->errors[] = 'Invalid Email';  return count($this->errors)? 0 : 1;  }  public function valid_token()  {   if(!isset($_SESSION['token']) || $this->token != $_SESSION['token'])	 $this->errors[] = 'Invalid Submission';   return count($this->errors)? 0 : 1;  }}?>

thanks..Edited:Now tested the login.php and get this error...

Notice: Undefined index: token in C:\xampp\htdocs\login_scripts\class.login.php on line 20Members Area
I am logged in..though...Edited again...sorryJust checked the database and found that the two new users have the same md5 hash..could that be because I am the same person logging in to test..I get the same hash???
Link to comment
Share on other sites

Deprecated: Function eregi() is deprecated in C:\xampp\htdocs\login_scripts\class.register.php on line 75Successfully Signed Up!
you can find for eregi() in line 75 and replace with preg_match(). eregi() is deprecated function. they discourage to use it anymore.
Just checked the database and found that the two new users have the same md5 hash..could that be because I am the same person logging in to test..I get the same hash???
You get the same hash because you had used the same password for that two username.
Link to comment
Share on other sites

Archived

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


×
×
  • Create New...