php登录模块不工作

标签 php mysql wamp web-deployment

我对 php-mysql 和网络编程知之甚少。对于我的项目工作,我制作了一个登录模块,它包含两个页面,但有一些错误。我将 WAMP 用于项目,每当我输入数据并按登录时,它不会转到 profile.php 页面, session 也不会启动。它在按下登录按钮后显示相同的页面 (login.php) 从最近两天开始,我一直在寻找这个错误,但我无法解决它。我的项目还有其他几页。这是我的代码。

登录.php

    <html>
<head>
<link rel="stylesheet" type="text/css" href="text.css" ></link>
<title>Login</title>
</head>

<body>
<div class="container" >
<div id="header" style="text-align: center;" >
<table width="500" align="center">
    <tr >
    <img src="logo.jpg"/>
    </tr>
</table>
</div>

<div>
<table class="form" align="center"  style="height:200px;padding-left:30px;float-align:center;margin-left=20px;margin-top:40px;margin-bottom:20px;text-align:;padding-left:20px;">
<form action="loginproc.php" method="POST">
<tr>
    <td align="center"colspan="780px" >
    <h3 style="font-family:Calibri; font-size: 22pt;font-weight: bold; color:#3B8C8C;text-align: center;">LOGIN</h3></td>
</tr>
<tr>
    <td>Email ID</td>
    <td><input type="email" name="emailid" maxlength="50" /></td>
</tr>
<tr>
    <td>Password</td>
    <td><input type="password" name="pwd" /></td>
</tr>
<tr>
    <td colspan="3" align="center" style="margin-bottom:20px;">
    <input type="submit" name="submit" class="button" value="Login" style="margin-bottom:20px;margin-top:20px;"/>
    <input type="reset" name="reset" class="button" value="Reset" style="margin-bottom:20px;margin-top:20px;"/>
</tr>   
</form></table></div>
</div>
</body>

</html>

loginproc.php

 <?php
if(isset($_REQUEST['submit']))
{
$server="localhost";
$user="root";
$password="";
$db="utility";
$con = mysql_connect($server,$user,$password);
if(!$con) 
{
    die("Cannot Connect".mysql_error());
}
else
    {
    if(!mysql_select_db($db,$con))
    {
    header('Location: login.php');
    }
    else
    {
    $email = isset($_POST['emailid'])? $_POST['emailid']:"";
    $email = mysql_real_escape_string($email);

    $password = isset($_POST['pwd'])? $_POST['pwd']:"";
    $password = mysql_real_escape_string($password);

    $access = "SELECT * FROM register WHERE (email = '$email') AND (password = '$password')";
    $access = mysql_query($access);
    $accessrow = mysql_num_rows($access);

    if($accessrow == 1)
    {
        include('session.php');
        $_SESSION['email'] = $email;
        header('Location: profile.php');
    }
    else
    {
        header('Location: home.php');   
    }
    mysql_close($con);
    }
}
}
?>

最佳答案

在您发布的代码中,您有一个前导空格,这将阻止您的 session 启动,因为必须在任何输出之前设置 session cookie。

*SPACE*<?php
if(isset($_REQUEST['submit']))
{

那个空格是您帖子中的错误,还是您的 login.php 文件中确实有这个空格?

关于php登录模块不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12517343/

相关文章:

php - 如何覆盖 Apache/PHP 存储在/tmp 中的文件的默认权限?

MySQL建表查询1064错误

localhost - WAMP:urls 中缺少 http://localhost/,wamp 项目链接错误

php - Azure 应用服务应用程序使用错误的 PHP 版本

php - AS3 从 PHP 接收数据

mysql - 需要一个有效的查询来从两个表中进行选择

PHP x64 不支持 x64 整数.. (Wamp & dropbox API)

apache - 在 WAMP 中制作漂亮的永久链接

php - 创建另一个 "Featured Image"选择器 wordpress

mysql - Pentaho 作业通信失败