Jump to content

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!

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.