【问题标题】:Error 403 connecting to localhost/<?=$_SERVER[%27PHP_SELF%27]?>连接到 localhost/<?=$_SERVER[%27PHP_SELF%27]?> 时出现错误 403
【发布时间】:2015-01-06 02:00:53
【问题描述】:

当我从我的登录或注册脚本重定向到 localhost/ 时收到 403 错误。

这是我的脚本:

登录:

    <html>
<center>
<head>
 <title>Login</title>
<font face="Courier" color="green">
<body background=background.png no-repeat center center fixed;
   -webkit-background-size: cover;
   -moz-background-size: cover;
   -o-background-size: cover;
   background-size: cover
   >

<h1>Login</h1>
<?php
if (!isset($_POST['submit'])){
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
 Username: <input type="text" name="username" /><br />
 Password: <input type="password" name="password" /><br />

 <input type="submit" name="submit" value="login" />
 </form>
 <?php
 } else{
 require_once("db_const.php");
 $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
 #check connection
 if ($mysqli->connect_errno) {
 echo "<p>MySQL error no {$mqsqli->connect_errno} : {$mysql->connect_error}</p>";
 exit();
}

$userame = $_POST['username'];
$password = $_POST['password'];

$sql = "SELECT * from users WHERE username LIKE '{$username}' AND password LIKE '[$password]' LIMIT 1";
$result = $mysqli->query($sql);
if (!$result->num_rows == 1) {
echo "<p>Invalid username/password combination</p>";
} else {
echo "<p>Logged in successfully</p>";

//do stuff
}
}
?>
 </font>
</body>
</center>
</html>

注册:

<html>
<head>
<title> Register </title>
</head>

<center>
<font face="courier"  color="green">
 <body background=background.png no-repeat center center fixed;
   -webkit-background-size: cover;
   -moz-background-size: cover;
   -o-background-size: cover;
   background-size: cover;
   >
<h1> Register</h1>

<?php
require_once("db_const.php");
if (!isset($_POST['submit'])) {
  ?>    



    <form action="  <?=$_SERVER['PHP_SELF']?>" method="post">
    Username: <input type="text" name="username" /><br />
    Password: <input type="password" name="password" /><br />
    Age: <select name="Age">
         <option value="12-13"> 12-13 </option>
         <option value="14-15"> 14-15 </option>
         <option value="16-17"> 16-17 </option>
         <option value="18+"> 18+ </option> 
         </select>
         <br />
   Gender: <select name="Gender">
         <option value="male"> male </option>
         <option value="female"> female </option> 
         </select>
         <br />


  <input type="submit" name="submit" value="register" />
 </form>
 </font>
</center>
<?php
} else {
 $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_AGE, DB_Gender);
 if ($mysqli->connect_errno)     {
echo "<p>MySQL error no {$mysqli->connect_errno} : {mysqli->connect_error}</p>";
exit();
}


# prepare data for insertion
$username = $_POST['username'];
$password =$_POST['password'];
$age =$_POST['Age'];
$gender =$_POST['Gender'];

$exists = 0;
$result = $mysqli->query("SELECT username from users WHERE username = '{$username}' LIMIT 1");
if ($result->num_rows == 1) {
$exists = 1;
}

if ($exists == 1)  echo "<p> Username already exists!</p>";
else {
      $sql = "INSERT INTO 'users' ('id', 'username', 'password', 'age', 'gender')
              VALUES (NULL, '{$username}', '{$password}', '{$age}'. '{$gender}')";

    if ($mysqli->query($sql)) {
    //echo "New Record has id" .$mysql->insert_id;
    echo "<p>Registered successfully!</p>";
    } else{
    echo "MySQL error no {mysql->errno} : {$mysql->error}</p>";
    exit();
    }
}
  } 
  ?>
    </body>
    </html> 

请见谅,先谢谢了!

另外,有些人可能会评论说我应该对我的密码进行散列或加盐,但这对于这个项目来说不是必需的。

【问题讨论】:

  • A 403 表示“拒绝访问”,这可能与您的脚本无关。检查您的网络服务器/网络主机设置/

标签: php login registration


【解决方案1】:

你必须在这一行使用echo

   action="<?php  echo $_SERVER['PHP_SELF']?>"

【讨论】:

  • 刚刚在注册文件上试过了。这是我得到的:Warning: mysqli::mysqli() expects parameter 5 to be long, string given in C:\wamp\www\btyse\register.php on line 46Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in C:\wamp\www\btyse\register.php on line 60Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in C:\wamp\www\btyse\register.php on line 70
  • 这是另一个错误兄弟,这不是关于你的问题,你必须搜索你的新问题,或者只是考虑一下!
猜你喜欢
  • 2020-04-04
  • 2014-08-01
  • 2020-03-13
  • 1970-01-01
  • 2016-04-19
  • 2016-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多