PHP代码和网站在localhost上运行但在服务器上不起作用

时间:2018-06-30 07:06:54

标签: php html mysqli

美好的一天,我在本地主机wamp服务器上构建的登录脚本在本地主机上运行良好,但是自从将其上传到服务器以来,它一直无法正常运行。它会读取用户名和密码,如果正确,则不执行任何操作,但如果输入错误,则会警告我这是错误的。如果正确,应该将我重定向到主页。自从在服务器上以来,我一直在为此奋斗。请任何将提供帮助的人将不胜感激。我的注册页面也做同样的事情。它注册但不提供任何反馈,也不会重定向到登录页面,但是在localhost上一切正常 登录脚本                                 

                    <?php
                    include 'connection.php';
                    if(isset($_SESSION['use']))   // Checking whether the session is already there or not if 
                                                  // true then header redirect it to the home page directly 
                     {
                        header("Location:home.php"); 
                     }

                    if(isset($_POST['login']))   // it checks whether the user clicked login button or not 
                    {
                         $user = $_POST['code'];
                         $pass = $_POST['user'];
                             if(!filter_var($_POST['code'], FILTER_VALIDATE_EMAIL)) {
                        echo "<script>alert('invalid Email Address')</script>" ; // Use your own error handling ;)
                    }

                        if (!preg_match("/^[a-zA-Z0-9 ]*$/",$pass)) {
                          echo "<script>alert('Invalid password. Only letters, numbers and white space allowed')</script>" ;
                        }
                         // Secure the credentials

                        // Check the users input against the DB.
                    $user = stripslashes($user);
                    $pass = stripslashes($pass);


                    $check=mysqli_query($conn, "SELECT * FROM userregister WHERE email = '$user'  AND password = '$pass'");
                        $checkrows=mysqli_num_rows($check);
                        if($checkrows>0){  
                      while( $row = mysqli_fetch_assoc($check) ){
                       $_SESSION['use']=$row['email'];  

                              header("Location:home.php");
                              //  On Successful Login redirects to home.php

                            }}

                            else
                            {
                                    echo "<script>alert('Incorrect Login details')</script>" ;
                                    header("refresh:0");      
                            }
                    }
                     ?>
                    <html>
                    <head>
                        <title>Prediction Home</title>
                        <link rel="stylesheet" type="text/css" href="style.css">
                        <link rel="icon" type="image/png" href="2.png">
                      <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
                      <link rel="stylesheet" type="text/css" href="w3.css">
                    </head>
                    <body>
                    <div class="topnav" id="myTopnav">
                      <a href="index.php">Prediction Home</a>
                      <a href="javascript:void(0);" class="icon" onclick="myFunction()">X
                      </a>
                    </div>
                    <div>
                        <h4>Enter your Log-In details</h4>
                    </div>
                    <div class="form">
                      <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
                        <label for="E-mail">E-mail</label>
                        <input type="text" id="E-mail" name="code" required="required">
                        <label for="">Password</label>
                        <input type="password" id="" name="user" required="required">
                        <input type="submit" name="login" value="Log-In">
                      </form>
                      <p>Forgot Password? <a class="button" href="forgotpass.php"><span>Click Me!</span></a></p>
                    </div>

                    <script>
                    function myFunction() {
                        var x = document.getElementById("myTopnav");
                        if (x.className === "topnav") {
                            x.className += " responsive";
                        } else {
                            x.className = "topnav";
                        }
                    }
                    </script>

                    </body>
                    </html>

注册脚本

         <!doctype html>
                    <html>
                    <head>
                        <title>Prediction Home</title>
                        <link rel="stylesheet" type="text/css" href="style.css">
                        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
                      <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
                      <link rel="stylesheet" type="text/css" href="w3.css">
                        <link rel="icon" type="image/png" href="2.png">
                    </head>
                    <body>
                    <div class="topnav" id="myTopnav">
                      <a href="index.php">Prediction Home</a>
                      <a href="javascript:void(0);" class="icon" onclick="myFunction()">X
                      </a>
                    </div>
                    <div>
                        <h2>REGISTRATION PAGE</h2>
                    </div>
                    <div class="form">
                      <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
                        <label for="fname">FULL NAME</label>
                        <input type="text" name="option" required="required">
                        <label for="Email">E-mail</label>
                        <input type="text" name="option1" required="required">
                        <label for="pass">PASSWORD</label>
                        <input type="password"  name="password" required="required">
                        <label for="pass2">RE-ENTER PASSWORD</label>
                        <input type="password" name="password2" required="required">
                        <input type="submit" name="register" value="Register">
                      </form>
                       <p>Already Registerd? <a class="button" href="login.php"><span>Sign In</span></a></p>
                    </div>
                    <div id="page"></div>
                    <footer style="background-color: purple ">
                    <div style="text-align: center">  
                    <h2>Quick Links</h2> 
                    <a style="vertical-align: middle;color: white" href="index.php">Prediction Home</a>   
                    <a style="vertical-align: middle;color: white" href="contact.php">Contact Us</a>
                    <a style="vertical-align: middle;color: white" href="Store.php">My Store</a>  
                    <a style="vertical-align: middle;color: white" href="basic.php">Basic</a> 
                    <a style="vertical-align: middle;color: white" href="regular.php">Regular</a> 
                    <a style="vertical-align: middle;color: white" href="weekend.php">Weekend</a>   
                    <a style="vertical-align: middle;color: white" href="about.PHP">About</a>
                    <a style="vertical-align: middle;color: white" href="conditions.PHP">Terms & Conditions</a>

                    </div> 

                    <div style="text-align: center;">  

                    <h2>Contacts:</h2> 
                    <p style="color: white;vertical-align: middle">Call Us On:08136668621 <br>
                     MAil:user@predicthome.com</p>
                    <a href="https:/twitter.com/predicthome" class="fa fa-twitter"></a>
                    <a href="https://www.instagram.com/predictionhome/" class="fa fa-instagram"></a>
                    <a href="mailto:user@predictionhome.com" class="fa fa-yahoo"></a>


                    </div>

                    <div style="color: yellow;text-align: center;">Prediction Home &copy; <?php echo date("Y");?></div> 
                    </footer>
                    <script>
                    function myFunction() {
                        var x = document.getElementById("myTopnav");
                        if (x.className === "topnav") {
                            x.className += " responsive";
                        } else {
                            x.className = "topnav";
                        }
                    }
                    </script>
                    <?php
                    include 'connection.php';
                    if(isset($_POST['register']))   // it checks whether the user clicked login button or not 
                    {
                         $option = $_POST['option'];
                         $option1 = $_POST['option1'];
                          $password = $_POST['password'];
                         $password2 = $_POST['password2'];
                             if(!filter_var($_POST['option1'], FILTER_VALIDATE_EMAIL)) {
                        echo "<script>alert('invalid Email Address')</script>" ; // Use your own error handling ;)
                        }
                        if (!preg_match("/^[a-zA-Z0-9 ]*$/",$option)) {
                          echo "<script>alert('Invalid NAME. Only letters, numbers and white space allowed')</script>" ;
                        }   
                         if (!preg_match("/^[a-zA-Z0-9 ]*$/",$password)) {
                          echo "<script>alert('Invalid password. Only letters, numbers and white space allowed')</script>" ;
                        }
                            if (!preg_match("/^[a-zA-Z0-9 ]*$/",$password2)) {
                          echo "<script>alert('Invalid password. Only letters, numbers and white space allowed')</script>" ;
                        }
                        if ($password !=$password2) {
                           echo "<script>alert('Password does not match')</script>" ;
                        }
                         // Secure the credentials

                      // Check the users input against the DB.

                      $insert=mysqli_query($conn,"SELECT * FROM userregister WHERE email='$option1'");
                    $insertrows=mysqli_num_rows($insert);
                    if($insertrows>0 || $password !=$password2|| !preg_match("/^[a-zA-Z0-9 ]*$/",$password) || !filter_var($_POST['option1'], FILTER_VALIDATE_EMAIL) ){
                      echo "<script>alert('Email already exists or Invalid Email address')</script>" ;
                    }
                     else {
                      $check="INSERT IGNORE INTO userregister(name,email,password) VALUES('$option','$option1','$password')";
                    if ($conn->query($check) === TRUE) {
                      header("refresh:0;url=login.php");
                       echo "<script>alert('registered')</script>" ;


                       $to = "$option1";
                    $subject = "Account Registration Successful";
                    $body = "Hi $option, Welcome to Predict Home. Your Favourite Site to select the best of Games that wll Bring you Good money\r\nWe hope we keep in touch and hear from you more often. \r\nVisit our site regularly to view our predicted Games from our highly acclaimed analysts.\r\nOnce again you are Welcome.\r\nPredict Home Admin";
                    $lheaders= "From: <user@predicthome.com>";
                    mail($to, $subject, $body, $lheaders);

                    }
                    }   


                    //send email


                    }
                     ?>
                    </body>
                    </html>

3 个答案:

答案 0 :(得分:-1)

更改服务器中的PHP版本。它必须类似于本地服务器中的PHP版本

答案 1 :(得分:-1)

我没有任何评论的声誉,所以我将尝试给出答案。

检查您的connection.php文件,并验证主机名等是否正确。

由于未正确设置数据库,很可能无法连接到数据库,因此它将检查您告诉脚本的错误,但不会执行数据库部分(查询)。

答案 2 :(得分:-1)

检查是否已按照与localhost文件夹中相同的方式将文件存储在服务器上。

编辑:

 if(isset($_SESSION['use']))  
                     {
                        header("Location:home.php"); 
                     }

这里的变量“ use”是什么?看起来您已经复制了代码,却忘记了更改变量名,这就是为什么它没有重定向到正确的页面。