doutian4046 2013-01-13 02:56 采纳率: 0%
浏览 58
已采纳

PHP:strlen()不起作用......完全没有

I've tried looking at other answers, but all I come across is people placing their comparison operators in the wrong direction. Not the case here. Below is a simplified version of my code. This code does not return the error I believe it SHOULD.

I'm trying to determine if a string, in this case a password, meets a minimum length requirement. However, it never gives the error it should, regardless of the string I put in. As a means of debugging, I tried inputting a simple string, "hi" into strlen() and told it to give an error if it was less than 6 bytes long. However, even that wouldn't return as I wanted it to.

I feel like I'm missing something silly. Help?

<?php
$Email = mysql_real_escape_string(Trim($_POST['Email']));
$Password = "hi";

// check fields
$error = false;
if(empty($Email)) $error = true;
if(strlen(utf8_decode($Password)) < 6) $error = true;

if($error != false) header("Location: index.php?error=true");


// store user to database
$success = insert_dbUser(new User($Email, $Password));

// redirect to success page 
if ($success) {
    header("Location: index.php?success=true");
}
else header("Location: index.php?error=existinguser");
?>
  • 写回答

2条回答 默认 最新

  • drfif48428 2013-01-13 02:59
    关注

    Make sure to end the script after sending location headers:

    if ($error) {
        header("Location: index.php?error=true");
        exit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?