pneudralics Posted May 11, 2009 Share Posted May 11, 2009 //$idf gets primary id from database //$idsessionf gets idsession from database which is randomly generated when registration setcookie ('id', $idf['id']); setcookie ('idsession', $idsessionf['idsession']); //redirects to user page user page if(!isset($_COOKIE['id']) && !isset($_COOKIE['idsession'])){ //error } { //else yay! } When the broser prompts me to allow the cookie it always shows 1 character in the data section, even if 'id' as more than 1 character and 'idsession' is sha1 Link to comment https://forums.phpfreaks.com/topic/157723-solved-why-is-my-cookies-only-setting-1-character-in-the-data-section-of-the-cookie/ Share on other sites More sharing options...
jackpf Posted May 11, 2009 Share Posted May 11, 2009 I don't think you're giving setcookie() all the parameters it requires, such as expiry date, path and domain. Could be a reason. Link to comment https://forums.phpfreaks.com/topic/157723-solved-why-is-my-cookies-only-setting-1-character-in-the-data-section-of-the-cookie/#findComment-831832 Share on other sites More sharing options...
revraz Posted May 11, 2009 Share Posted May 11, 2009 Those are all optional and if omitted: Would destroy the cookie when the browser is closed. Only work on the current path of the page. Only work on the current domain. Link to comment https://forums.phpfreaks.com/topic/157723-solved-why-is-my-cookies-only-setting-1-character-in-the-data-section-of-the-cookie/#findComment-831836 Share on other sites More sharing options...
jackpf Posted May 11, 2009 Share Posted May 11, 2009 Yeah, true, it doesn't require them, but...it's probably why it isn't working Link to comment https://forums.phpfreaks.com/topic/157723-solved-why-is-my-cookies-only-setting-1-character-in-the-data-section-of-the-cookie/#findComment-831839 Share on other sites More sharing options...
revraz Posted May 11, 2009 Share Posted May 11, 2009 Replace your variables with a string value and see how it works. If that works, echo your variables and verify they are what you think they are. Link to comment https://forums.phpfreaks.com/topic/157723-solved-why-is-my-cookies-only-setting-1-character-in-the-data-section-of-the-cookie/#findComment-831841 Share on other sites More sharing options...
pneudralics Posted May 11, 2009 Author Share Posted May 11, 2009 //does not work setcookie ('id', $idf['id']); setcookie ('idsession', $idsessionf['idsession']); //works... setcookie ('id', $idf); setcookie ('idsession', $idsessionf); Now the issue is how do I check for $idf and $idsessionf? //This doesn't work anymore if(!isset($_COOKIE['id']) && !isset($_COOKIE['idsession'])){ //error } { //else yay! } Link to comment https://forums.phpfreaks.com/topic/157723-solved-why-is-my-cookies-only-setting-1-character-in-the-data-section-of-the-cookie/#findComment-831862 Share on other sites More sharing options...
jackpf Posted May 11, 2009 Share Posted May 11, 2009 if(!isset($_COOKIE['id']) && !isset($_COOKIE['idsession'])){ //error } else { //else yay! } Should work. Link to comment https://forums.phpfreaks.com/topic/157723-solved-why-is-my-cookies-only-setting-1-character-in-the-data-section-of-the-cookie/#findComment-831867 Share on other sites More sharing options...
pneudralics Posted May 11, 2009 Author Share Posted May 11, 2009 I got it! It did work. One of my require page was still including $_SESSION instead of $_COOKIE so it was throwing the error page. Thanks for all the help. Link to comment https://forums.phpfreaks.com/topic/157723-solved-why-is-my-cookies-only-setting-1-character-in-the-data-section-of-the-cookie/#findComment-831882 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.