Jump to content

[SOLVED] cookies disallowed... what about sessions?


Dragen

Recommended Posts

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

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.