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
Avatar of Shinesh Premrajan
Shinesh Premrajan
Flag of India image

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
Avatar of rgb192
rgb192
Flag of United States of America image

ASKER

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
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
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

"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
Avatar of rgb192
rgb192
Flag of United States of America image

ASKER

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"]))
        {
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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

Avatar of rgb192
rgb192
Flag of United States of America image

ASKER

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

Array ( ) array(0) { }
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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
Avatar of rgb192
rgb192
Flag of United States of America image

ASKER

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
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

So maybe that cookie is used by the CMS to recognize the "session" information?  Without seeing the code we are only guessing.
Avatar of rgb192
rgb192
Flag of United States of America image

ASKER

and it is difficult for me to show, because I cant find it
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
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of rgb192
rgb192
Flag of United States of America image

ASKER

thanks
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo