?
Solved

Why my hosting session is not accessible in other pages?

Posted on 2014-02-20
8
Medium Priority
?
609 Views
Last Modified: 2014-02-21
I have bought new hosting package (linux, php) for my product site. In this hosting ,I'm facing session sharing/accessing problem in sub pages/ folders. How to resolve this?

I have tested single session in same page, it works.. but when I access the session variable in other pages , it shows empty.  What could be the problem ? Please advise.

This works fine (same page)
<?php
session_start();

print_r ($_REQUEST);

 if($_REQUEST['usr']=="ABC" && $_REQUEST['pswd']=="123"){

 $_SESSION['usr'] = "ABC";
 $_SESSION['pswd'] = "123";
 
 print_r ($_SESSION);
 exit;
 
 header("Location: content.php");
 
 }
 else{
 header("Location: niceform.php");
 }
?>

Open in new window


Here it is not working,

<?php
session_start();

print_r ($_SESSION);

if(!isset($_SESSION['usr']) || !isset($_SESSION['pswd'])){
 header("Location: niceform.php");
} 
 include 'logoff.html';

?>

Open in new window

0
Comment
Question by:Loganathan Natarajan
  • 5
  • 3
8 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 1500 total points
ID: 39876061
I modified your code a bit and you can see it work here:  http://www.dibsplace.info/index.php  When you're 'logged in' it goes to http://www.dibsplace.info/content.php and when you're logged out it goes to http://www.dibsplace.info/niceform.php

index.php
<?php
session_start();

//print_r ($_REQUEST);

if($_REQUEST['usr']=="ABC" && $_REQUEST['pswd']=="123"){

 $_SESSION['usr'] = "ABC";
 $_SESSION['pswd'] = "123";
 
 //print_r ($_SESSION);
 //exit;
 
 header("Location: content.php");
 }
 
 else{
 $_SESSION['usr'] = "";
 $_SESSION['pswd'] = "";
 
 header("Location: niceform.php");
 }
?>

Open in new window


content.php
<?php
session_start();

print_r ($_SESSION);

if(!isset($_SESSION['usr']) || !isset($_SESSION['pswd'])){
 header("Location: niceform.php");
} 

include 'logoff.html';

?>

Open in new window


logoff.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>logoff.html</title>
</head>
<body>
<h1>logoff.html</h1>
<p>But we're really logged in?</p>
<a href="index.php">index.php</a><br />
or login <a href="index.php?usr=ABC&pswd=123">index.php?usr=ABC&pswd=123</a><br />

or logout <a href="index.php?usr=v&pswd=9">index.php?usr=v&pswd=9</a>

</body>
</html>

Open in new window


niceform.php
<?php
session_start();

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>niceform.php</title>
</head>
<body>
niceform.php<br />
We're logged out.<br />

<a href="index.php">index.php</a><br />
or login <a href="index.php?usr=ABC&pswd=123">index.php?usr=ABC&pswd=123</a><br />
or logout <a href="index.php?usr=v&pswd=9">index.php?usr=v&pswd=9</a><br />

<?php print_r ($_SESSION);
 ?>
</body>
</html>

Open in new window

0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 39876167
Thanks, Let me check
0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 39876232
@ Dave Baldwin

I checked it looks empty again. Check the attachment.

I think session is not working the hosting.  Can you tell me how to inform them to fix?
err1.png
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39876274
Try this to see if it is generating a session_id.
<?php
session_start();

$sessid = session_id();

echo $sessid;
?>

Open in new window

0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 39876324
yes , it is generating,
75c7b35536c97069ec7ce6eec9e696fbArray
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39876347
Does it generate the same number if you refresh the page several times?  Or does it change?  Do you have cookies enabled in your browser?
0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 39876356
Thanks Dave for your support so far.

I just found solution that session_path is not defined in the hosting and configured now
. Now it is working fine.

75c7b35536c97069ec7ce6eec9e696fbArray ( [Yii.CCaptchaAction.3c85ef20.site.captcha] => kanuqij [Yii.CCaptchaAction.3c85ef20.site.captchacount] => 2 [products] => [92d77c121165b256e0981213cac80aa3id] => 1 [userid] => 1 [92d77c121165b256e0981213cac80aa3userType] => Administrator [usr] => ABC [pswd] => 123 )
logoff.html

But we're really logged in?
index.php
or login index.php?usr=ABC&pswd=123
or logout index.php?usr=v&pswd=9

Open in new window

0
 
LVL 36

Author Closing Comment

by:Loganathan Natarajan
ID: 39876360
This helped to test my session on hosting. Thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question