Avatar of rgb192
rgb192Flag for United States of America asked on

session_start()

I have a content management system that starts a session, defines and prints session variables

so, using the same domain name, I tried to print the session, without using or connecting to content management system
but session variable did not print

is session done by
'login name'
'url'



would
session_start()
delete all the current session variables

PHP

Avatar of undefined
Last Comment
rgb192

8/22/2022 - Mon
Shinesh Premrajan

Nope session_start() will initialize an session with a unique session id. If session already exist then this code will retain the same session in the defined page. to destroy a session use session_destroy()

Hope this helps
ASKER
rgb192

then could there be something in the content management system code to not include other sessions using the same domain name

is that what a login does
Shinesh Premrajan

yes it almost true, The login will first validates user authenticity then if the user is an valid one, then add user details from the user tables to session.

if you wish to see wt all details the session contains try this:

print_r($_SESSION);

Anywhere in the page, also in the top of the page, u must have the session_start() defined.

Hope this helps
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Ray Paseur

"then could there be something in the content management system code to not include other sessions using the same domain name"

You're in kind of a gray area with this question.  PHP sessions (almost invariably) involve the use of cookies.  The PHP session handler, by default, sets the cookies for the subdomain active at the time of the session_start() command.  If you have http://www.example.com and you try to use the session on http://example.com you may find that it does not work.  For the session to be started cross-subdomains, there is a little extra programming required beyond just saying session-start();

An example of a login system with explanations of how the parts work is available here:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
ASKER
rgb192

print_r($_SESSION);
only has output when I do it in the content management system


I am using subdomain.domain.com
so there is no www. vs non www.


the content management system uses

isset commands

like the ones in
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
        if (isset($_SESSION["entry_uri"]))
        {
Ray Paseur

When you say it "only has output..." -- what does the output or lack of output look like?

This kind of thing is one of the reasons I try to encourage programmers to use data visualization techniques, such as var_dump() and error_reporting(E_ALL).  If you install this script and run it you will see what I mean.

isset tests to see if a variable is set.
http://us3.php.net/manual/en/function.isset.php
<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);

// $_SESSION IS AN UNDEFINED VARIABLE BECAUSE WE DID NOT USE session_start();

// THIS WILL PRINT NOTHING
// print_r($_SESSION);

// PRINTS 'NULL'
var_dump($_SESSION);

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
rgb192

when I
add
session_start();
and
 uncomment lines 7,10

Array ( ) array(0) { }
Ray Paseur

Good, that makes sense.  

Without seeing the code, we are guessing about this.  Maybe the CMS destroys the session array (a security precaution?)  Maybe the CMS has a specialized or non-standard session handler.  Maybe the CMS has a different session name from the regular PHP session name.

Have you looked at the cookies to see what is set on the browser?  In Firefox you can find these with Tools => Options => Privacy
ASKER
rgb192

yes
there is
one cookie named by me
and
another cookie created by your script
named PHPSESSID

when I delete the cookie named by me,
I am logged out
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Ray Paseur

So maybe that cookie is used by the CMS to recognize the "session" information?  Without seeing the code we are only guessing.
ASKER
rgb192

and it is difficult for me to show, because I cant find it
Shinesh Premrajan

try this, using editplus do a search on the CMS folder for "session_start" (without quotes).

There may be many records, but lookout for the login page or any home page in the list of search results.

In that you can see whats the name of the session used. session_start("username") some thing i think from your comments above.

Hope this helps
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Ray Paseur

Something like this may be helpful to you when you are trying to debug this condition.
<?php // RAY_dump_session.php
error_reporting(E_ALL);

// START THE SESSION
session_start();

// DISPLAY THE VARS
echo "<pre>";

echo "_GET ";
var_dump($_GET);
echo PHP_EOL . PHP_EOL;

echo "_POST ";
var_dump($_POST);
echo PHP_EOL . PHP_EOL;

echo "_COOKIE ";
var_dump($_COOKIE);
echo PHP_EOL . PHP_EOL;


echo "_SESSION ";
var_dump($_SESSION);
echo PHP_EOL . PHP_EOL;

Open in new window

ASKER CERTIFIED SOLUTION
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
rgb192

thanks