Jump to content

Session not starting in server


kingb00zer
 Share

Recommended Posts

Ok I have this thing running perfect on xampp and on my old server. Now I have a private server and when I log into my site it doesnt recognise the session at all. I dont get it... here is the log in scripts this is checklogin.php

<?phpinclude("connection.php");$username= $_POST['username'];$password= $_POST['password'];// check if username and passwords match$checkuser= "SELECT * FROM users WHERE username = '$username' and password = '$password'";$result=mysql_query($checkuser);$count=mysql_num_rows($result);if ($count == 1){session_register($username);session_register($password);header("location:login_success.php");}else {include('loginfail.php');}?> 

this is login_success.php

<?session_start();if(session_register($username)){ // I also used session_is_registered($username) and $_SESSION['username']header("location:welcome.php");} else {echo "session not registering";}?>

I log in just fine and makeit all the way to the welcome page (even further) but no session related variables appear. for example on the welcome page it should say "hello admin, wlecome.... etc" instead it says "hello , welcome.... etc" I cant work out why xampp runs it but my server doesnt.

Link to comment
Share on other sites

I had the version downgraded a couple of days ago to 5.2.0 but I am looking to remove depreciate functions where I can this is what I ahve now and the same thing is happeningchecklogin.php

<?phpinclude("connection.php");$username= $_POST['username'];$password= $_POST['password'];// check if username and passwords match$checkuser= "SELECT * FROM users WHERE username = '$username' and password = '$password'";$result=mysql_query($checkuser);$count=mysql_num_rows($result);if ($count == 1){$_SESSION['$username'];$_SESSION['$password'];header("location:login_success.php");}else {include('loginfail.php');}?> 

login_success.php

<?session_start();if(!$_SESSION['$username']){header("location:welcome.php");} else {echo "session not registering";}?>

I originaly had it the other way than !$_SESSION['$username'] and that just sent me to my not registering echo so I threw in the ! to see and it logs me i as a nameless user

Edited by KingB00ZeR
Link to comment
Share on other sites

You also need to start session in checklogin.php

$_SESSION['$username']; $_SESSION['$password'];
You are not assigning the value here which always be null. and as you expected $username never will evaluate the value if it is in single quotes. it will evaluate if it is in double quotes. but it would be better to do like this $_SESSION['username']=$username;on successfull login and then in loginsuccess page you can use isset() to see $_SESSION['username'] is there or not. You can also use $_SESSION['username'] to later on in other pages to show username. Edited by birbal
Link to comment
Share on other sites

I dont understand but just a day later without any changes to what is supposed to be working log in scripts I am back to where I was and this time even my xampp wont run it.... here is the code below checklogin.php

<?php session_start();include("connection.php");$username= $_POST['username'];$password= $_POST['password'];// check if username and passwords match$checkuser= "SELECT * FROM users WHERE username = '$username' and password = '$password'";$result=mysql_query($checkuser);$count=mysql_num_rows($result);if ($count == 1){$_SESSION["$username"];$_SESSION["$password"];header("location:login_success.php");}else {include('loginfail.php');}?> 

login_success.php

<?php session_start();if(isset($_SESSION['username'])){header("location:welcome.php");} else {echo "session not registering";}?> 

I get the session not registering echo happening when I log in. And liek I said before it was working a day earlier...

Edited by KingB00ZeR
Link to comment
Share on other sites

as has been pointed out now, this isn't really doing anything

 $_SESSION["$username"];$_SESSION["$password"];

as has been just suggested, assign values to them. At this point though, do you need to keep their password in $_SESSION though?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...