Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

PHP session set but not being detected

php session error login

Best Answer JakeWelton, 07 October 2013 - 09:40 AM

I've now performed some more tests. I wanted to actually see if there are any other characters being stored in this string, so i split the string into an array and counted the array. The array has 32 elements when it should have 19. This means somehow theres 13 addition characters which i'm unable to see.

 

all of the additional elements seem to be empty.

 

Any more ideas? This is proving to be quite difficult.

 

 

 

 

SOLVED

I finally solved this problem. Turns out somehow some hidden ASCII control characters where getting in there. Thanks to this page here I was able to use the following code to remove these characters then the comparison worked perfectly.

 

Code to remove hidden ASCII control characters:

preg_replace('/[\x00-\x1F\x7F]/', '', $input);
Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1 JakeWelton

JakeWelton

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 152 posts

Posted 06 October 2013 - 10:01 AM

Hi,

 

I seem to have a problem which I have never encountered before. I'm hoping someone out there can help me in some way.

 

I have a simple login system which is working off sessions. Now, when the user logs in, the session gets set so that we have a way of checking to see who has access to what etc... Now on another page, i'm doing a simple check which goes as follows:

if(!isset($_SESSION['My Session']))
{
   echo "User not logged in.";
}
else
{
   echo "User is logged in.";
}

Now for some reason, its saying the user is not logged in when they are. I firstly thought maybe the session is not being set so I did the following:

echo '<pre>';
var_dump($_SESSION);
echo '</pre>';

The output from this was:

 

array(1) {
["My Session"]=>
string(1) "2"
}

 

Which means the session is being set correctly. My question is, why is the IF statement saying its not set??? It makes no sense to me. Can anyone else help?

 

Thanks.


Edited by welton122, 06 October 2013 - 10:01 AM.

sig.jpg

"Before you judge someone, walk a mile in their shoes; after that, who cares?! Their a mile away and you've got their shoes!"


#2 speculatius

speculatius

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 106 posts

Posted 06 October 2013 - 11:35 AM

Once it happened to me, that there was hidden character in my array index. Like 'My Session´┐Ż', but invisible. Check file encoding, then try to remove your IF condition and write it again by hand.


Edited by speculatius, 06 October 2013 - 11:41 AM.


#3 JakeWelton

JakeWelton

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 152 posts

Posted 06 October 2013 - 12:49 PM

Once it happened to me, that there was hidden character in my array index. Like 'My Session´┐Ż', but invisible. Check file encoding, then try to remove your IF condition and write it again by hand.

 

I think you are onto something here with this. To tell the truth, the value is not simply typed into the function, its actually inputted in the form of a variable. I've performed tests for many things such as determining the type of variable (e.g. string, int etc...) and it said string (what i would expect), i've tested for hidden characters and had no luck with that, stripping any white space away from the edges...

 

The system functions correctly if i type the value in so there must be a fault with the variable somewhere. 

 

Can you think of any other tests to perform on this variable? 


sig.jpg

"Before you judge someone, walk a mile in their shoes; after that, who cares?! Their a mile away and you've got their shoes!"


#4 CMR

CMR

    CC Regular

  • Member
  • PipPipPip
  • 30 posts

Posted 06 October 2013 - 07:48 PM

Did you already put session_start(); at the beginning of the page? And adding error_reporting(E_ALL); doesn't show any error?


Constant changing == Technology


#5 JakeWelton

JakeWelton

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 152 posts

Posted 06 October 2013 - 09:55 PM

Did you already put session_start(); at the beginning of the page? And adding error_reporting(E_ALL); doesn't show any error?

 

Yes the first line on the page is the session_start() method and the next one below that is the error reporting method which i did have set to -1. However i just tried setting it to E_ALL and still no error messages unfortunately.


sig.jpg

"Before you judge someone, walk a mile in their shoes; after that, who cares?! Their a mile away and you've got their shoes!"


#6 speculatius

speculatius

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 106 posts

Posted 07 October 2013 - 03:59 AM

You can use mb_detect_encoding to check that variable. Comparision of strings in different encodings is not working as expected. There is nothing else I can think about :(



#7 JakeWelton

JakeWelton

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 152 posts

Posted 07 October 2013 - 09:13 AM

You can use mb_detect_encoding to check that variable. Comparision of strings in different encodings is not working as expected. There is nothing else I can think about :(

 

The character encoding being used is ASCII, which i believe to be correct????


Edited by welton122, 07 October 2013 - 09:35 AM.

sig.jpg

"Before you judge someone, walk a mile in their shoes; after that, who cares?! Their a mile away and you've got their shoes!"


#8 JakeWelton

JakeWelton

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 152 posts

Posted 07 October 2013 - 09:40 AM   Best Answer

I've now performed some more tests. I wanted to actually see if there are any other characters being stored in this string, so i split the string into an array and counted the array. The array has 32 elements when it should have 19. This means somehow theres 13 addition characters which i'm unable to see.

 

all of the additional elements seem to be empty.

 

Any more ideas? This is proving to be quite difficult.

 

 

 

 

SOLVED

I finally solved this problem. Turns out somehow some hidden ASCII control characters where getting in there. Thanks to this page here I was able to use the following code to remove these characters then the comparison worked perfectly.

 

Code to remove hidden ASCII control characters:

preg_replace('/[\x00-\x1F\x7F]/', '', $input);

Edited by welton122, 07 October 2013 - 10:08 AM.

sig.jpg

"Before you judge someone, walk a mile in their shoes; after that, who cares?! Their a mile away and you've got their shoes!"





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download