douwen9540 2014-04-10 14:51
浏览 55

密码保护网页

Title may be a little misleading but I'll try to explain here. Basically, when I put my website in 'offline mode' I have a section where admins can log in with a password. (They are not logging in with their accounts) The password is 'password' for this example. When a user types in the correct password, it should redirect them to the webpage, howvever it isn't, it's just echoing 'Incorrect password' - when it is in fact correct.

The code is made up by me, as you can probably tell. I expected this not to work because I'm still in the very early stages of learning PHP

HTML:

<div class="backdroplogin">
  <h2>Login to your account:</h2>
  <form action="/Offline" method="GET">
    <input type ="password" name="password_login" size="25" Value="" />
    <input type="submit" name="login" value="Login" />
</div>
  </form>

PHP:

//ADMIN LOGIN
$password = "AbCd0987connekt£*^%";

if (isset($_GET["password_login"])) {
   $password_login = $_GET["password_login"];

   if ($password_login == $password) {
   header("Location:/Admin/Panel");
 } else {
   echo "Incorrect password";
 }
 }

Thanks for any help.

  • 写回答

3条回答 默认 最新

  • dtwxmn8741 2014-04-10 15:06
    关注

    Like Svetlio said.. It is a bad habit to send passwords using the get method. So instead use method="post" in your html form and $_POST["password_login"] in your php.

    In your text you say you use "password" as the password for this tool, while in your php you check if the sent password is equal to "AbCd0987connekt£*^%", so if you put in your password you should use "AbCd0987connekt£*^%"... or did you mean you use "$password"

    Just another tip: for readability ability of your code try to indent :)

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法