2 Replies - 248 Views - Last Post: 02 November 2013 - 01:03 AM Rate Topic: -----

#1 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • Posts: 171
  • Joined: 07-October 12

Session Variable is Not Setting.

Posted 01 November 2013 - 10:20 PM

I have a session variable I'm trying to set off of a SQL Query for Login. For my Page that I want to check for a users logged in status it currently is set to
<?php

if($_SESSION['username']=='') {
	echo "Not Logged IN";
	}
else {
echo $_SESSION['username'];
}
?>


And then for my PHP script that logs the user on I have
session_start();

$email = $_POST['email'];
$password = $_POST['password'];
$con = mysqli_connect("localhost","root","g278535814","DoxCMS");
$query = "SELECT * FROM user WHERE email='$email' AND password='$password'";
$result = mysqli_query($con,$query);
$num_rows=mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
if($num_rows==1)
{
$_SESSION['email']=$_POST['email'];
$_SESSION['username']=$row['username'];
$_SESSION['permissions']=$row['permissions'];
echo $_SESSION['username'];
echo "true";

}
else{

}


I pulled my function to simply reload the page to go to my login function and within it if I put
$_SESSION=$row['username'];
echo $_SESSION['username'];


And then when it runs to the login page it shows my username, so I'm lost as to why it's not actually setting my Login Session

Is This A Good Question/Topic? 0
  • +

Replies To: Session Variable is Not Setting.

#2 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • Posts: 171
  • Joined: 07-October 12

Re: Session Variable is Not Setting.

Posted 01 November 2013 - 11:26 PM

Quick Update:
I was able to get a session variable to set as
$_SESSION['loggedIn']="True";


I placed that in my Success, and it set with no issues. My username Session Variable sets, BUT only for that page, the instant I leave that page it's unsetting for some reason. Not sure as to why...

And the last update. After About 2 and a half hours or so I realized that I should slap myself.
        foreach (glob("include/functions.d/*.php") as $Functions)
        {
                include $Functions;
        }



When you're including all your functions in one folder. Ensure that you make the logout a function and NOT just the php script. >.>
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3494
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Session Variable is Not Setting.

Posted 02 November 2013 - 01:03 AM

View PostDoxramosPS, on 02 November 2013 - 07:26 AM, said:

And the last update. After About 2 and a half hours or so I realized that I should slap myself.
        foreach (glob("include/functions.d/*.php") as $Functions)
        {
                include $Functions;
        }


this is when you learn to love autoloading.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1