doupu1949 2013-10-02 18:21
浏览 20
已采纳

会话变量不能在不同的页面上工作

Once i logged in i set a session variable inside body element(inside login.php) as below:

session_start();
$_SESSION['Username'] = $_POST["Username"];

if(isset($_SESSION['Username']))
    $loginTrue = 1;
else
    $loginTrue = 0;

and on top every page i have added this

<?php 
session_start();          //this was added after seeing many suggestions in stack overflow that session_start() has to be called at the top on each page. Though i tot calling once was sufficient.
if(isset($_SESSION['Username']))
    $loginTrue = 1;
else
    $loginTrue = 0;
?>

Now whenever i redirect my page after login from login.php $_SESSION['Username'] gets unset, i dont know how. I redirect using a button click as in onclick execute window.location = home.php

  • 写回答

2条回答 默认 最新

  • douza6300 2014-08-22 10:04
    关注

    alright guys i solved it somehow. I dont know how i did but i did. Firstly i created 4 webpages, a small one just to check the if session variables are supported. Once i confirmed this then i did the below and my original webpage started working session start is very important at top of all pages. Also try session activity in different browsers. Also check by closing dreamweaver. Also make sure is used instead of transitional and stuff and also that session start comes before doctype html declaration

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?