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 6176977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:11:37+00:00 2026-05-24T00:11:37+00:00

Ok here is my problem: When a user logs into my site I put

  • 0

Ok here is my problem:
When a user logs into my site I put all their user info into a session like this

session_start();
//Put all user info into session cookie
$_SESSION["login"] = 'true';
$_SESSION["id"] = $user_info['id'];
$_SESSION["firstname"] = $user_info['firstname'];
$_SESSION["lastname"] = $user_info['lastname'];
$_SESSION["screen_name"] = $user_info['screen_name'];
$_SESSION["facebook"] = $user_info['facebook'];
$_SESSION["email"] = $user_info['email'];
$_SESSION["date_joined"] = $user_info['date_joined'];
$_SESSION["account_type"] = $user_info['account_type'];
$_SESSION["account_active"] = $user_info['account_active'];
$_SESSION["hashed_password"] = $user_info['hashed_password'];

The problem is if they logged in from http://www.domain.com and then end up on a page at domain.com or the other way around they login from domain.com and end up on a page at http://www.domain.com the info stored in the session is not available.

How can I have the session info available no matter if they logged in with www or not?

@ Mr. Grossman

Would it be proper to do something like this:

    <?php
    //Ok I modified the code so I don't get the undefined errors I was getting

//OLD CODE
    //$currentCookieParams = session_get_cookie_params(); 
    //$rootDomain = '.domain.com'; 
    //session_set_cookie_params( 
        //$currentCookieParams["3600"], 
        //$currentCookieParams["/"], 
        //$rootDomain, 
        //$currentCookieParams["false"], 
        //$currentCookieParams["false"] 
    //); 

    //session_name('mysessionname'); 

//NEW CODE
    $rootDomain = '.beckerfamily1.com'; 
    session_set_cookie_params( 3600, '/', $rootDomain, false, false); 
    session_start();

    if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 2700)) {
        // last request was more than 45 min ago
        if(isset($_SESSION['id'])){
        $connection = mysql_connect('localhost', '******', '*******');
        if (!$connection){
            die('Database connection failed: ' . mysql_error());
            }
        $db_select = mysql_select_db('beckerfamily');
            if(!$db_select){
                die('Could not select database: ' . mysql_error());
                }
        $query = "UPDATE users SET online='no' WHERE id='{$_SESSION['id']}' LIMIT 1";
        $result = mysql_query($query);
        if (!$result) {
                die("Database query failed: " . mysql_error());
            }
        }
            $_SESSION = array();
            if(isset($_COOKIE[session_name()])) {
                setcookie(session_name(), '', time()-42000, '/');
            }
        session_destroy();   // destroy session data in storage
        session_unset();     // unset $_SESSION variable for the runtime
        if(isset($connection)){
            mysql_close($connection);
            }
     }
    $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
    ?>

Also is it necessary to have session_name('mysessionname'); or can I just omit that and PHP will set the session name on its own?

  • 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-05-24T00:11:38+00:00Added an answer on May 24, 2026 at 12:11 am

    Cookies (like the PHPSESSID cookie) are only available on the domain they were set on. You can make the domain include all subdomains:

    ini_set('session.cookie_domain', '.example.com' );
    

    or if configuration does not allow you to override that,

    $currentCookieParams = session_get_cookie_params(); 
    
    $rootDomain = '.example.com'; 
    
    session_set_cookie_params( 
        $currentCookieParams["lifetime"], 
        $currentCookieParams["path"], 
        $rootDomain, 
        $currentCookieParams["secure"], 
        $currentCookieParams["httponly"] 
    ); 
    
    session_name('mysessionname'); 
    session_start(); 
    

    http://php.net/manual/en/function.session-set-cookie-params.php

    Even better might be to choose whether you want your site accessed through www or not, and redirect all requests to the other.

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

Sidebar

Related Questions

This is in reference to the question previously asked The problem here is, each
Here's a problem I ran into recently. I have attributes strings of the form
Here's my problem - I'd like to communicate between two websites and I'm looking
I have a weird quirk with cookies in IE. When a user logs into
As I see it there are two different types of logging: User-focused logs, like
Here's the problem I'm having, I've got a set of logs that can grow
Here is the problem. Every single library I develop logs something, however I don't
Hey all, have a slight problem here. In CakePHP I have a controller that
I'm working on an e-commerce application. When a user logs into my app, I
I've got a problem here with an MSI deployment that I'm working on (using

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.