Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9314769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:13:01+00:00 2026-06-19T02:13:01+00:00

I am trying to set sessions using PHP in my login script although it

  • 0

I am trying to set sessions using PHP in my login script although it doesn’t seem to be setting any sessions. I’m setting all sessions to be written to the path ‘/’. I am using AJAX to log in.

Start_secure_session function:

function start_secure_session() {
    $session_name = "CodeCluster";
    $http_only = true;
    $https = false;
    ini_set("session.use_only_cookies", 1);
    $cookie_parameters = session_get_cookie_params();
    session_set_cookie_params($cookie_parameters['lifetime'], "/", $cookie_parameters['domain'], $https, $http_only);
    session_name($session_name);
    session_start();
    session_regenerate_id(true);
}

Login Function :

function login($email, $password, $database) {

try {

    $query = $database -> prepare("SELECT id, email, password, salt, activated FROM members WHERE email = :email LIMIT 1");

    $query -> execute(

        array(
            "email" => $email
        )

    );

    $info = $query -> fetch();

    if(strlen($info[0]) > 0) {

        if(account_is_locked($info['id'], $database)) {

            echo "<response>Your account is locked, please try again in two hours!</response>";

            exit();

        } else {

            if($info['activated'] == 1) {

                $password = hash('sha512', $password.$info['salt']);

                if($password === $info['password']) {

                    $_SESSION['cc_id'] = $info['id'];

                    $_SESSION['cc_email'] = $info['email'];

                    $_SESSION['cc_login_string'] = hash('sha512', $password.$_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']);

                    $last_login = time();

                    $query = $database -> prepare("UPDATE members SET last_login = :last_login WHERE id = :id LIMIT 1");

                    $query -> execute(

                        array(
                            "last_login" => $last_login,
                            "id"              => $info['id']
                        )

                    );

                    return true;

                    exit();

                } else {

                    $query = $database -> prepare("INSERT INTO login_attempts(user_id, ip_address, attempt_time) VALUES (:id, :ip, :time)");

                    $query -> execute(

                        array(

                            "id" => $info['id'],
                            "ip" => $_SERVER['REMOTE_ADDR'],
                            "time" => time()

                        )

                    );

                    echo "<response>Email or password is incorrect! Please check your credentials!</response>";

                    exit();

                }

            } else {

                echo "<response>Please activate your account! You should have received an email with an activation link!</response>";

                exit();

            }

        }


    } else {

        echo "<response>Account with those details does not exist!</response>";

        exit();

    }

} catch(PDOException $e) {

    echo "<response>We could not log you in; A report of the error has been sent to tech support!</response>";

    mail("codecluster.official@gmail.com", "CodeCluster Login Error", "Login Error; Timestamp @ " . time() . " ; IP Address : " . $_SERVER['REMOTE_ADDR'] . " ;\r\n" . $e);

    exit();

}

}

is_user_logged_in function :

function is_user_logged_in($database) {

if(isset($_SESSION['cc_id'], $_SESSION['cc_email'], $_SESSION['cc_login_string'])) {

    try {

        foreach ($_SESSION as $session) {
            strip_tags($session);
        }

        $query = $database -> prepare("SELECT password FROM members WHERE id = :id AND email = :email LIMIT 1");

        $query -> execute(

            array(

                "id" => $_SESSION['cc_id'],
                "email" => $_SESSION['cc_email']

            )

        );

        if(strlen($query -> fetch()) > 0) {

            $password = $query -> fetch();

            $password = hash("sha512", $password.$_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']);

            if($password == $_SESSION['cc_login_string']) {

                return true;

            } else {

                return false;

            }


        } else {

            return false;

        }

    } catch(PDOException $e) {

        mail("codecluster.official@gmail.com", "Code-Cluster Error", "Error occured whilst checking users logged in status; Timestamp @ ". time() . " ; \r\n" . $e);

        return false;

        exit();

    }

} else {
    return false;

}

 }

When I do if(is_user_logged_in($database)) {header("Location: home.php"); exit();} it does not redirect me. I have tested and it seems that the script can’t find the sessions which lead me to believe that they’re null.

Is there any reason why this is acting like this?

EDIT: I just did a var_dump on $_SESSION on the index.php and it printed out :
array(3) { [“cc_id”]=> string(1) “6” [“cc_email”]=> string(24) “toxiclogic@hotmail.co.uk” [“cc_login_string”]=> string(128) “This is redacted because it is a hashed password” }

EDIT: This is not being resolved by the ‘Headers being sent’ question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:13:03+00:00Added an answer on June 19, 2026 at 2:13 am

    Do not output anything before using header() and session_start().

    Check for whitespaces as well.

    Encode your files into UTF-8 without BOM.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do a simple test php script for sessions. Basically it increments
i am using Cakephp1.3 and i am trying to set value in app_controller.php under
I'm trying to build a site that runs without refreshes, using Jquery and PHP
Using cake acl I am trying to set permissions for logged in users. I
I'm having some trouble using sessions with php.. I think I have figured out
I am trying to set the HTML title of a page dynamically from PHP.
I'm trying to submit a page onto itself by using php echo $_SERVER['PHP_SELF']; but
I am trying to write a PHP script that will create an HTML form
Trying to post a status update using facebook php sdk. Code posted below. As
I am trying to recover the content of MySQL binary log file using PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.