session - Undefined variable: _SESSION in the redirected PHP file -
i quite new php. trying write login script in php. index.html file takes username , password , submits form login.php. login.php file checks if user registered , creates session if so. after redirects file controlpanel.php
my problem proper values on reading session variable in login.php(just before redirecting controlpanel.php). in controlpanel.php, when seek read session variable gives error:
( ! ) notice: undefined variable: _session in d:\work\projects\phpapp\myecom\admin\controlpanel.php on line 2
my code:
login.php
<?php if(!isset($_session)){ob_start(); session_start(); }else{error_log("session set");} require_once("../config/config.php"); ?> <?php require_once("../classes/autoload.php"); $objuser = new user(); if (isset($_post["username"])){ $username = $_post["username"]; $pass = $_post["password"]; error_log("about check registration"); if($objuser->isregistereduser($username, $pass, 2)){ error_log("user registered"); login::loginuser($objuser->id, 2); error_log("session id in login.php: " . $_session["uid"]); header("location:controlpanel.php"); } else{ error_log("not registered"); //redirect registration page } } ?>
controlpanel.php
<?php if(!isset($_session)){ error_log("session not set"); }else{ error_log("session set in controlpanel: " . $_session["uid"]); } ?>
php error_log:
[25-oct-2014 18:08:51 europe/paris] check registration
[25-oct-2014 18:08:51 europe/paris] user registered
[25-oct-2014 18:08:51 europe/paris] session id in login.php: 1
[25-oct-2014 18:08:51 europe/paris] session not set
you didn't start session in controlpanel.php
script.
always phone call session_start();
before using $_session
.
php session
No comments:
Post a Comment