2016-09-24 105 views
-1

我已經登錄和註冊系統,並在我的本地主機上它工作正常,但是當我託管它並創建帳戶它說不正確的憑據。如果需要,我會發送一個代碼。我已經創建了一個MySql數據庫。PHP託管時無法正常工作

網站鏈接:http://metallicafanpage.esy.es

我使用Hostinger

<?php 
ob_start(); 
session_start(); 
require_once 'dbconnect.php'; 

// it will never let you open index(login) page if session is set 
if (isset($_SESSION['user'])!="") { 
    header("Location: home.php"); 
    exit; 
} 

$error = false; 

if(isset($_POST['btn-login'])) { 

    // prevent sql injections/ clear user invalid inputs 
    $email = trim($_POST['email']); 
    $email = strip_tags($email); 
    $email = htmlspecialchars($email); 

    $pass = trim($_POST['pass']); 
    $pass = strip_tags($pass); 
    $pass = htmlspecialchars($pass); 
    // prevent sql injections/clear user invalid inputs 

    if(empty($email)){ 
    $error = true; 
    $emailError = "Please enter your email address."; 
    } else if (!filter_var($email,FILTER_VALIDATE_EMAIL)) { 
    $error = true; 
    $emailError = "Please enter valid email address."; 
    } 

    if(empty($pass)){ 
    $error = true; 
    $passError = "Please enter your password."; 
    } 

    // if there's no error, continue to login 
    if (!$error) { 

    $password = hash('sha256', $pass); // password hashing using SHA256 

    $res=mysql_query("SELECT userId, userName, userPass FROM users WHERE userEmail='$email'"); 
    $row=mysql_fetch_array($res); 
    $count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row 

    if($count == 1 && $row['userPass']==$password) { 
    $_SESSION['user'] = $row['userId']; 
    header("Location: home.php"); 
     } else { 
     $errMSG = "Incorrect Credentials, Try again..."; 
     } 

     } 

    } 
    ?> 

這裏是Register.php

<?php 
ob_start(); 
session_start(); 
if(isset($_SESSION['user'])!=""){ 
    header("Location: home.php"); 
} 
include_once 'dbconnect.php'; 

$error = false; 

if (isset($_POST['btn-signup'])) { 

    // clean user inputs to prevent sql injections 
    $name = trim($_POST['name']); 
    $name = strip_tags($name); 
    $name = htmlspecialchars($name); 

    $email = trim($_POST['email']); 
    $email = strip_tags($email); 
    $email = htmlspecialchars($email); 

    $pass = trim($_POST['pass']); 
    $pass = strip_tags($pass); 
    $pass = htmlspecialchars($pass); 

    // basic name validation 
    if (empty($name)) { 
    $error = true; 
    $nameError = "Please enter your full name."; 
    } else if (strlen($name) < 3) { 
    $error = true; 
    $nameError = "Name must have atleat 3 characters."; 
    } else if (!preg_match("/^[a-zA-Z ]+$/",$name)) { 
    $error = true; 
    $nameError = "Name must contain alphabets and space."; 
    } 

    //basic email validation 
    if (!filter_var($email,FILTER_VALIDATE_EMAIL)) { 
    $error = true; 
    $emailError = "Please enter valid email address."; 
    } else { 
    // check email exist or not 
    $query = "SELECT userEmail FROM users WHERE userEmail='$email'"; 
    $result = mysql_query($query); 
    $count = mysql_num_rows($result); 
    if($count!=0){ 
    $error = true; 
    $emailError = "Provided Email is already in use."; 
    } 
    } 
    // password validation 
    if (empty($pass)){ 
    $error = true; 
    $passError = "Please enter password."; 
    } else if(strlen($pass) < 6) { 
    $error = true; 
    $passError = "Password must have atleast 6 characters."; 
    } 

    // password encrypt using SHA256(); 
    $password = hash('sha256', $pass); 

    // if there's no error, continue to signup 
    if(!$error) { 

    $query = "INSERT INTO users(userName,userEmail,userPass) VALUES('$name','$email','$password')"; 
    $res = mysql_query($query); 

    if ($res) { 
    $errTyp = "success"; 
    $errMSG = "Successfully registered, you may login now"; 
    unset($name); 
    unset($email); 
    unset($pass); 
    } else { 
    $errTyp = "danger"; 
    $errMSG = "Something went wrong, try again later..."; 
    } 

    } 


} 
?> 
+0

是的。顯示你的代碼。 –

+0

有代碼@SanzeebAryal。如果你需要更多隻是寫我會送你。這對我來說非常重要。 –

+1

用戶註冊情況如何?注:不建議使用mysql_ *函數。 –

回答

1

這是因爲你的PHP MySQL版本您的主機服務器只是使用舊的Php或Mysql版本