Jump to content

Recommended Posts

For some reason my session's gets lost randomly, or my scripting is buggy.

 

When i hit refresh it just looses the session, how can i debug this?

 

Here is the login script.

 

<?php

session_start();

include('mysql_connect.php');

include('../functions/encryption.php');

 

$username = $_POST['usernameFormLogin'];

$password = $_POST['passwordFormLogin'];

 

$encryptPassword = encryptStringArray($password);

 

$sql = "SELECT * FROM registeredUsers WHERE username='" . mysql_real_escape_string($username) . "' AND password='" . mysql_real_escape_string($encryptPassword) . "'";

$result = mysql_query($sql);

 

$count = mysql_num_rows($result);

 

if ($count == 1){

$_SESSION['WSuser'] = encryptStringArray($username.'|'.$encryptPassword);

$succesLoginUsername = 'http://cpanel.mysite.com';

}

else {

$errorLoginUsername = '<p>Error Username or Password does not match</p>';

}

 

mysql_close();

 

echo json_encode(array(

'errorLoginUsername'=>''.$errorLoginUsername.'',

'succesLoginUsername'=>''.$succesLoginUsername.'',

));

 

?>

 

Which then redirects to the homepage which has the following code

 

<?php

session_start();

include('_include/catch/mysql_connect.php');

include('_include/functions/encryption.php');

// dycrypt the authentication

$fetchSecure = decryptStringArray($_SESSION['WSuser']);

// digest the authentication

list($WSusername, $WSpassword) = explode("|", $fetchSecure);

// check if user authentication

$sql = "SELECT * FROM registeredUsers WHERE username='" . mysql_real_escape_string($WSusername) . "' AND password='" . mysql_real_escape_string($WSpassword) . "'";

$result = mysql_query($sql);

$row = mysql_fetch_array($result);

$count = mysql_num_rows($result);

if ($count == 1){

$_SESSION['WSvalidUser'] = '1';

}else{$_SESSION['WSvalidUser'] = '0';}

?>

Link to comment
https://forums.phpfreaks.com/topic/266978-problems-with-loss-on-session-data/
Share on other sites

When i tried to retrieve the session data after that quirky effect, the session['WSvalidUser'] was null, this can only happen if the user is invalid or that the session['WSuser'] is empty.

 

But after i relogged in all session data is there.

 

So as far as i can tell the session is definitely not expired, otherwise session['WSvalidUser'] would be expired too.

 

So it seems that when refreshing something its clearing the session['WSuser']

 

What i will do now is write some other sessions see if they are still there, after it looses WSuser session

 

I'll keep post back soon with the update and if it worked what im planning.

Hiya,

 

Thanks for the reply, indeed there is no check on the login file thanks for pointing that out. Will update that.

 

Regarding the other page it is very very odd, i have now with the help of the session dump, figured out that it shows the sessions, then it's gone, then after a couple of minutes it's there again and so on...

 

I cant understand how that is even possible???

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.