954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Strlen not working ... :(

Hi,

I'm having a little problem with a password Reset Script I've made

The script sends you a reset hash to your email to confirm that you requested the password reset. This resethash is just a random string with letters and numbers that is 15 chars long

Problem is, when I verify if it is 15 chars long, the script is telling me it isn't

// ...

$hash = $_GET['hash'];
    
if(strlen($hash) == 0) { $msg[] = "Hash Field is empty !"; }
elseif(strlen($hash) !== 15) { $msg[] = "Hash is invalid !"; }
    
if(count($msg) == 0)
{
     // ....
}


Here is a test URL with a valid Reset Hash http://virtualtrader.cuonic.tk/resetpass.php?hash=APraKgfg0l0QqwC

What is wrong ? Thanks in advance ;)

cuonic
Junior Poster in Training
56 posts since Mar 2011
Reputation Points: 16
Solved Threads: 9
 

Isn't not equal

!=


as opposed to

!==
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Tried

And failed... Still get Hash Is Invalid D:

I get the same when I do

<?php

if($_GET)
{
	include("includes/mysql.php");
	
	$hash = $_GET['hash'];
	
	if(strlen($hash) == 0) { $msg[] = "Hash Field is empty !"; }
	elseif(strlen($hash) > 15) { $msg[] = "Hash is invalid !"; } // This is where it fails D:
	elseif(strlen($hash) < 15) { $msg[] = "Hash is invalid !"; }
	
	echo strlen($hash); // This shows 15
	
	if(count($msg) == 0)
	{
		// ....
	}

?>
cuonic
Junior Poster in Training
56 posts since Mar 2011
Reputation Points: 16
Solved Threads: 9
 

From the above snippet how do you know it is failing on the >15 as opposed to the <15

Both output the same message?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Ok problem is no longer there, it is now a MySQL Problem :

<?php
		$hash = mysql_real_escape_string($hash);
		$query = mysql_query("SELECT username, email FROM user_db WHERE resethash='$resethash'");
		if(mysql_num_rows($query) == 0) { $msg[] = "Hash is incorrect !"; }
?>


It just echos "Hash is incorrect" even though it is valid and correctly inserted into database

cuonic
Junior Poster in Training
56 posts since Mar 2011
Reputation Points: 16
Solved Threads: 9
 

is $resethash a variable or the actual string name?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Wow i can't believe I didn't spot that... I put $resethash instead of $hash

I hate myself x)

Thanks for your help anyway

cuonic
Junior Poster in Training
56 posts since Mar 2011
Reputation Points: 16
Solved Threads: 9
 

dont hate yourself, plenty of others will do it for you. :)

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: