douhan4093 2014-07-14 18:38
浏览 66

为什么我的代码在一台服务器上运行,而在另一台服

The following code works on my university server just fine but doesn't work on a private one that I have paid for.

The problem lies in the:

            header("Location: products.php");
        }
    } else {
        echo "Invalid username or password!";
    }

If I enter the wrong name/password the code echo's as expected. But if the user enters their details correctly, nothing happens at all!

I am new to PHP so I don't know where to start to troubleshoot but I have tried replacing the "header("Location: products.php");" with an echo but with no avail still.

I have also considered that the PHPmyadmin servers might be different versions or the character encoding might be causing some of this trouble.

Here is the full code.

Any help would be absolutely appreciated!

<?php

if(isset($_POST["submit"])){
    $user=$_POST['user'];
    $pass=$_POST['pass'];
    $username = "";
    $password = "";
    $hostname = ""; 
    $md5pass = md5($pass);

    //connection to the database
    $dbhandle = mysqli_connect($hostname, $username, $password);

    $con=mysql_connect($hostname, $username, $password) or die(mysql_error());
    $select=mysql_select_db("l1233156", $con) or die("cannot select DB");

    $query=mysql_query("SELECT * FROM login WHERE username='".$user."' AND password='".$md5pass."'");
    $numrows=mysql_num_rows($query);
    if($numrows!=0)
    {
        while($row=mysql_fetch_assoc($query))
        {
            $dbusername=$row['username'];
            $dbpassword=$row['password'];
        }

        if($user == $dbusername && $md5pass == $dbpassword)
        {
            session_start();
            $_SESSION['sess_user']=$user;

            /* Redirect browser */
            header("Location: products.php");
        }
    } else {
        echo "Invalid username or password!";
    }
}
?><!doctype html> 
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="main.css"/>
</head>
<body>
<div class="center">
<p><a href="register.php">Register</a> | <a href="login.php">Login</a></p>
<h3>Login Form</h3>
<form action="" method="POST">
Username: <input type="text" name="user"><br />
Password: <input type="password" name="pass"><br /> 
<input type="submit" value="Login" name="submit" />
</form>
</div>
</body>
</html>

EDIT: This is what I managed to grab from the error logs.

[Mon Jul 14 10:30:34.134187 2014] [autoindex:error] [pid 28718:tid 140153014126336] [client 86.153.7.34:55032] AH01276: Cannot serve directory /home/joesadmin123/public_html/productreviews/: No matching DirectoryIndex (index.html.var,index.htm,index.html,index.xhtml,index.wml,index.perl,index.pl,index.plx,index.ppl,index.cgi,index.jsp,index.js,index.jp,index.php4,index.php3,index.php,index.phtml,index.shtml,default.htm,default.html,home.htm,index.php5,Default.html,Default.htm,home.html,welcome.html) found, and server-generated directory index forbidden by Options directive

  • 写回答

1条回答 默认 最新

  • duanposhi3641 2014-07-14 18:46
    关注

    - try using meta tag refresh -

    <?php
    if($user == $dbusername && $md5pass == $dbpassword)
    {
    session_start();
    $_SESSION['sess_user']=$user;
    ?>
    <html>
      <head>
        <META http-equiv="refresh" content="5;URL=/<?php echo 'products.php'; ?>">
      </head>
      <body>
      </body>
    </html>
    <?php
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度