-1

This is the login.php,

with the local host my web site is working properly. However, on server it is not working. The web site is conecting with DB and checking the user, email, password, but the session is not starting. I have checked already the PHP version from both, localhost and server. They are the same version php 7.4. I have no Idea how to fix this problem, if you know how to fix it, I have already paid some people with more experience to fix it. but they didn't fix. so if you can help me to solve it please contact me and we can negotiate it.

thanks all


require_once 'php/dbconfig.php';


class USER
{

    private $conn;

    public function __construct()
    {
        $database = new Database();
        $db = $database->dbConnection();
        $this->conn = $db;
    }

    public function runQuery($sql)
    {
        $stmt = $this->conn->prepare($sql);
        return $stmt;
    }

    public function register($fname, $mname, $lname, $uname, $dob, $pnumber, $streetname, $number, $city, $state, $postcode, $country, $umail, $upass, $usertype )
    {
        try
        {
            $new_password = password_hash($upass, PASSWORD_DEFAULT);

            $stmt = $this->conn->prepare("INSERT INTO customers(FName,MName, LName, UserName, DOB, PNumber, StreetName, Number, City, State, PostCode, Country, Email, Password, UserType)
                                  VALUES(:fname, :mname, :lname, :uname, :dob, :pnumber, :streetname, :number, :city, :state, :postcode, :country, :umail, :upass, :usertype)");


            $stmt->bindparam(":fname", $fname);
            $stmt->bindparam(":mname", $mname);
            $stmt->bindparam(":lname", $lname);
            $stmt->bindparam(":uname", $uname);
            $stmt->bindparam(":dob", $dob);
            $stmt->bindparam(":pnumber", $pnumber);
            $stmt->bindparam(":streetname", $streetname);
            $stmt->bindparam(":number", $number);
            $stmt->bindparam(":city", $city);
            $stmt->bindparam(":state", $state);
            $stmt->bindparam(":postcode", $postcode);
            $stmt->bindparam(":country", $country);
            $stmt->bindparam(":umail", $umail);
            $stmt->bindparam(":upass", $new_password);
            $stmt->bindparam(":usertype", $usertype);


            $stmt->execute();

            return $stmt;
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }


    public function doLogin($uname,$umail,$upass)
    {
        try
        {
            $stmt = $this->conn->prepare("SELECT CustomerID, UserType, UserName, FName, LName, Email, Password FROM customers WHERE UserName=:uname OR Email=:umail");

            $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail,));

            $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
            if($stmt->rowCount() == 1)
            {
                if(password_verify($upass, $userRow['Password']))
                {
                    $_SESSION['user_session'] = $userRow['CustomerID'];
                    $_SESSION['user_name']= $userRow['UserName'];
                    $_SESSION['user_fname']= $userRow['FName'];
                    $_SESSION['user_lname']= $userRow['LName'];
                    $_SESSION['user_usertype']= $userRow['UserType'];



                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }

    public function is_loggedin()
    {
        if(isset($_SESSION['user_session']))
        {
            return true;
        }
    }

    public function redirect($url)
    {
        header("Location: $url");
    }

    public function doLogout()
    {
        session_destroy();
        unset($_SESSION['user_session']);
        return true;
    }
}
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Welcome to Stackoverflow. Please format your code correctly using the editor, this is unreadable. – rx2347 Mar 07 '20 at 04:07

1 Answers1

0

Add session_start(); start of the page.

<?php
session_start();  //add this line 
require_once 'php/dbconfig.php';
Tushar
  • 568
  • 3
  • 13