Jump to content

PHP session question


TFT2012

Recommended Posts

Hi, I have question about the PHP session.

 

First, I have the site directory like this:

 

-- root

---- classes

-------- auth.php

-------- curldata.php

---- includes

-------- longin.php

---- index.php

---- dashboard.php

---- readapc.php

 

The index.php has the login form:

<form action="includes/login.php" method="post">

 

If login is successful, the login.php will do:

require_once ("../classes/auth.php");
if ( success)
{
$_SESSION["logged"] = true;
$_SESSION["user"] = array information
// The user information array is returned from "auth.php".
header("Location: ../dashboard.php");
}
else
header("Location: ../index.php");

 

In dashboard.php, it will display the $_SESSION['user'] data correctly. If clicking the link to readapc.php inside dashboard.php, the $_SESSION['user'] is good as well.

 

The problem happened when I do the following code inside "readapc.php": (It is okay if I don't do this)

require_once ("classes/curldata.php");
$result = data retrieved from curldata.php;
$_SESSION['data'] = $result;

If I do the things above, when I click the readapc.php, the session data is gone, readapc.php does NOT show $_SESSION['user'] data no more. (I am in readapc.php page now). But the $_SESSION['data'] is displayed well.

 

Then, if I click dashboard.php link, it will jump to login page (index.php) because I setup

if (!isset($_SESSION['logged']))
header("Location: index.php")

on all index.php, dashboard.php, and readapc.php.

 

Could anyone give me a hand on this problem? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/274426-php-session-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.