简体   繁体   中英

PHP session not set in some files

I have some trouble with PHP Sessions. I was searching too much for answers, most had problems at sesson_start() function, that is not the case here I guess.

Index.php, Loginback.php, UserInfo.php all start with:

<?php session_start(); ?>

There is index.php where I have login form with action loginback.php:

<form action="loginback.php"  method="POST" id="LoginForm">
    <input type="text" name="UserName" placeholder="Username" class="form-control"/>
    <input type="password" name="Password"  placeholder="Password"  class="form-control"/>
    <input type="submit" name="submit" value="Login" id="LoginButton" class="btn btn-info, OASButton" />
</form>

at LoginBack.php is validation for user input, if everything is OK I say:

$_SESSION["user"] = "Temo"; //string is for testingpurposes 
header("location: http://website.com/mine/index.php");

after redirecting at index.php If session is set I include "statistics.php" and it works just fine, if session is not set I incldue "logreg.php"- also works fine, but when I go to userinfo.php and check for session isset it always says no:

<?php session_start(); ?>
<?php  
if(isset($_SESSION['user'])==true){ 
       echo "Logged In!";
 } else {    
   echo "Not Logged in";} ?>

So bottom line, session is recognized at index.php but not recognized at userid.php. Any help?

//sorry for my english.

'K , I have no idea what happened, I have not touched those files but now I am logged in but can't log out, here is logoutback.php where it should happen:

<?php session_start(); ?>
<?php 
session_unset(); 
session_destroy();

header("location: http://website.om/mine/index.php"); ?>

I've found an answer, for going to userinfo.php I had: <a href="http://www.website.com/mine/userinfo.php">

and that was the problem,

without www it works fine.

but also what was strange: I created folder SESSION just with session stuff and when I was starting session from there and redirecting through the same url, it was working. So anyways I't is finally over :)

在设置之前,您是否确定要在LoginBack.php包含session_start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM