We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,477 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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 ;)

3
Contributors
7
Replies
6 Hours
Discussion Span
2 Years Ago
Last Updated
8
Views
cuonic
Junior Poster in Training
69 posts since Mar 2011
Reputation Points: 18
Solved Threads: 11
Skill Endorsements: 0

Isn't not equal

!=

as opposed to

!==
iamthwee
Posting Genius
6,373 posts since Aug 2005
Reputation Points: 1,567
Solved Threads: 489
Skill Endorsements: 35

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
69 posts since Mar 2011
Reputation Points: 18
Solved Threads: 11
Skill Endorsements: 0

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 Genius
6,373 posts since Aug 2005
Reputation Points: 1,567
Solved Threads: 489
Skill Endorsements: 35

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
69 posts since Mar 2011
Reputation Points: 18
Solved Threads: 11
Skill Endorsements: 0

is $resethash a variable or the actual string name?

iamthwee
Posting Genius
6,373 posts since Aug 2005
Reputation Points: 1,567
Solved Threads: 489
Skill Endorsements: 35

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
69 posts since Mar 2011
Reputation Points: 18
Solved Threads: 11
Skill Endorsements: 0

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

almostbob
Nearly a Senior Poster
3,303 posts since Jan 2009
Reputation Points: 585
Solved Threads: 403
Skill Endorsements: 7

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0769 seconds using 2.69MB