doutian4046 2013-01-13 02:56
浏览 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条)

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题