Dragen Posted September 24, 2007 Share Posted September 24, 2007 Hi, I know that sessions are, in effect, cookies, so what I'm wondering is, if someone has cookies disallowed on their browser, does that also mean that I can't use the $_SESSION variable? I'm sure this is a simple question with a simple answer! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/70532-solved-cookies-disallowed-what-about-sessions/ Share on other sites More sharing options...
sstangle73 Posted September 24, 2007 Share Posted September 24, 2007 easy way to check do it when i turned cookies off the sessions didnt set Quote Link to comment https://forums.phpfreaks.com/topic/70532-solved-cookies-disallowed-what-about-sessions/#findComment-354324 Share on other sites More sharing options...
Dragen Posted September 24, 2007 Author Share Posted September 24, 2007 Yeah that's kinda what I thought, but just wanted to check that it wasn't my computer playing up Bit of a problem though, because I'm trying to set a cookie and I needed to check if I had already tried to set it previously, so I was going to create a session variable with a value of 1 if I've tried to create the variable. Otherwise my code goes round in a continuous loop. Can anyone take a peek at this and suggest how I could check if I've already tried setting the cookie (and failed): <?php function get_res(){ if(isset($_COOKIE['screen_res'])){ $res = $_COOKIE['screen_res']; return $res; }else){ $d = mktime(date('G'), date('i')+1, date('s'), date('m'), date('j'), date('Y')); $d = date('D M j Y G:i:s \G\M\T', $d); ?> <script language="javascript"> <!-- writeCookie(); function writeCookie() { var date = new Date('<?php echo $d; ?>'); date.setDate(date.getDate()) var the_cookie_date = date.toGMTString(); var the_cookie = "screen_res="+ screen.width +"x"+ screen.height; var the_cookie = the_cookie + ";expires=" + the_cookie_date; document.cookie=the_cookie location = '<?php echo $_SERVER['REQUEST_URI']; ?>'; } //--> </script> <?php return ''; } } If javascript is disabled it's no problem, because it the returns blank, but if javascript is enabled it tries to set the cookie, then (because I need to read from the cookie) I reload the page. Obviously when I reload the page I need a way of telling that It's already gone through the process, otherwise it loops through the function indefinitly. Quote Link to comment https://forums.phpfreaks.com/topic/70532-solved-cookies-disallowed-what-about-sessions/#findComment-354335 Share on other sites More sharing options...
Dragen Posted September 24, 2007 Author Share Posted September 24, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/70532-solved-cookies-disallowed-what-about-sessions/#findComment-354387 Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2007 Share Posted September 24, 2007 cookies are not required for sessions. Quote Link to comment https://forums.phpfreaks.com/topic/70532-solved-cookies-disallowed-what-about-sessions/#findComment-354390 Share on other sites More sharing options...
rarebit Posted September 24, 2007 Share Posted September 24, 2007 http://usphp.com/manual/en/ref.session.php A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL. This means you have to add a session id onto every link, this needs to be named PHPSESSID, e.g. www.a.co.uk?PHPSESSID=007ABCETC700AETC The id will be harvested automatically when session_start() is called. However this method is warned against! Quote Link to comment https://forums.phpfreaks.com/topic/70532-solved-cookies-disallowed-what-about-sessions/#findComment-354402 Share on other sites More sharing options...
Dragen Posted September 24, 2007 Author Share Posted September 24, 2007 Thanks rarebit! That's great. I'm only using to store info on a link to an image, so I'm not concerned about displaying the session id really so that works great for me! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/70532-solved-cookies-disallowed-what-about-sessions/#findComment-354412 Share on other sites More sharing options...
rarebit Posted September 24, 2007 Share Posted September 24, 2007 Check it works because php.ini can stop it, session.use_only_cookies, session.use-trans-sid... Quote Link to comment https://forums.phpfreaks.com/topic/70532-solved-cookies-disallowed-what-about-sessions/#findComment-354417 Share on other sites More sharing options...
Dragen Posted September 24, 2007 Author Share Posted September 24, 2007 I've already checked and it works fine. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/70532-solved-cookies-disallowed-what-about-sessions/#findComment-354421 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.