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

  • SEARCH
  • Home
  • 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 7835943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:53:27+00:00 2026-06-02T13:53:27+00:00

I have a php script that I call through ajax to initialize session variables

  • 0

I have a php script that I call through ajax to initialize session variables for a user login. When I retrieve the session info later on it doesn’t seem to be there. What is missing from this. I must say I am assuming that the $_SESSION variable is there. I haven’t done this before.

PHP code that searches for user in db and initializes session variable

while (true) {
    $md5_pw = md5($password_text);
    $r_getuser = mysql_query("SELECT * FROM users WHERE (user_name = BINARY '".mysql_real_escape_string($l_un_em)."' OR email = '".mysql_real_escape_string($l_un_em)."') AND (password = '$md5_pw' OR temp_password = '$md5_pw') AND status >= 0");
    if (mysql_num_rows($r_getuser) == 0) {
        /* echo $messages['log_un_em_pw_incorrect'];
        return; */
        $return['return_code'] = -1;
        $return['return_msg'] = $messages['log_un_em_pw_incorrect'];
        echo json_encode($return);
    }
    $row = mysql_fetch_assoc($r_getuser);
    /* if ($row['privs'] < 1) { echo $messages['log_no_privs']; break; } */
    if ($row['temp_password'] == $md5_pw) { //new password
        mysql_query("UPDATE users SET password = '".$md5_pw."', temp_password = NULL WHERE user_id = '{$row['user_id']}'");
    }
    $today = date('Y-m-d');
    if ($row['login_0'][0] == '9') { //first login
        mysql_query("UPDATE users SET login_0 = '".$today."', login_1 = '".$today."', login_cnt = 1 WHERE user_id = '{$row['user_id']}'");
    } else {
        mysql_query("UPDATE users SET login_1 = '".$today."', login_cnt = login_cnt+1 WHERE user_id = '{$row['user_id']}'");
    }
    $_SESSION['uid'] = $row['user_id'];
    $_SESSION['unm'] = stripslashes($row['user_name']);
    $_SESSION['uml'] = stripslashes($row['email']);
    $_SESSION['cL'] = $row['language'];
    /* echo '<meta http-equiv="refresh" content="0;url=livemass_CENTER34.php">'; */ //default page
    break;
}

PHP code to retrieve session variable.

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

echo 'user id '.$_SESSION['uid'].'<br/>';
echo 'username '.$_SESSION['unm'].'<br/>';
echo 'uml '.$_SESSION['uml'].'<br/>';
echo 'cL '.$_SESSION['cL'].'<br/>';

?>

Javascript to show session info.

$.ajax({
      url: "get_session_info.php",
      type: "GET",
      data: {},
      cache: false,
      async: false,
      success: function (response) {
      alert ('session info response <br/>'+response);
      },
});
  • 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-02T13:53:28+00:00Added an answer on June 2, 2026 at 1:53 pm

    add session_start() to all your files which access session varibale values

    <?php
    session_start();
    ini_set('display_errors', 1);
    
    // remaining items
    
    ?>
    

    http://php.net/manual/en/function.session-start.php

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

Sidebar

Related Questions

I have a php script that gets called via an ajax call. Values are
I have a PHP script that initialises an image gallery. It loops through all
I have a PHP script that loops through some urls. The urls are stored
I have a php script that truncates a string at 41 bytes. I call
I have php script that creates a temporary watermark image for users that are
I have a PHP script that runs as a CGI program and the HTTP
I have a PHP script that needs to determine if it's been executed via
I have a PHP script that can encode a PNG image to a Base64
I have a PHP script that sends critical e-mails. I know how to check
I have a PHP script that processes file uploads. The script tries to organise

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.