Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Why my hosting session is not accessible in other pages?

Posted on 2014-02-20
8
Medium Priority
?
606 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this article, we’ll look at how to deploy ProxySQL.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 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