vendredi 27 novembre 2015

PHP: login system not working in real world but works fine in WAMP/MAMP :(

I just finished building the first website in my life! Everything works fine in my MAMP/WAMP. So excited but when I am testing it in real environment today with hosting software C-Panel, but it turns out my login page doesn't work. The website does nothing when user submit the form where the user should be redirected to main.php.

My face turns from :) into :( just now. Below is my login.php, could anyone help to point out what might be the problem?

<?php if(!SESSION_id()) SESSION_start();?>
<html>
<head><title>login with your account</title></head>
<body>
    <form action="login.php" method="POST">
    <input type="text" name="email" placeholder="Email">
    <br>
    <input type="password" name="password" placeholder="Password">
    <br>
    <input type="submit" value="Log in" name="submit">
    </form>
</body>
</html>

<?php

require ("connect.php");



//declair the variable
$email=@$_POST["email"];
$password=@$_POST["password"];
//encrypt the password
$psw_en=sha1($password);

if(isset($_POST["submit"])){

    if($email || $password){
        if($email){
            if($password){ 
                $sql="select * from users where email='$email'";

                $result=mysqli_query($conn,$sql);
                $check_rows=mysqli_num_rows($result);

                    if ($check_rows !=0){
                         while ($row=mysqli_fetch_assoc($result)){
                            $db_email=$row["email"];
                            $db_psw_en=$row["password"];
                            $db_full_name=$row["full_name"];
                            $db_id=$row["user_id"];
                            $db_topics=$row["topics"];
                            $db_date_of_registration=$row["date_of_registration"];
                            $db_pic=$row["pic"];
                         }

                         if($email==$db_email&&$db_psw_en==$psw_en){
                            $_SESSION["id"] = $db_id;
                            $_SESSION["email"] = $email;
                            $_SESSION["full_name"] = $db_full_name;
                            $_SESSION["topics"] = $db_topics;
                            $_SESSION["date_of_registration"] = $db_date_of_registration;
                            $_SESSION["pic"] = $db_pic;
                            $_SESSION["password"] = $db_password;


                            header("Location: main.php");


                         }
                         else{
                            echo "password is wrong";
                         }

                    }
                    else {
                        echo "you are not registered,yet. Click here to <a href=\"register.php\">register</a>";
                    }

            }
            else{
                echo "it looks like password is empty";
            }
        }
        else{
            echo "it looks like email is empty";
        }
    }
    else{
        echo "it looks like everything is empty";
    }
}







?>




Aucun commentaire:

Enregistrer un commentaire