Page 1 of 1

help with cookie reading

Posted: Mon Nov 21, 2005 10:17 am
by vincenzobar
hi,

here is my PHP

Code: Select all

# This is a session tracker to provide for A/B testing on the website.
		session_start();
	
	# Initialize a random number
		srand ((float) microtime() * 10000256);
		
		# Define the array
		$whichdeal = array(1 => "4.0", 2 => "5.0"); //shortcut for below values start at 0
		
		# Choose the poison
		$random_key = array_rand($whichdeal);
		
		# Set the value of Dealinfo
		$dealnum = $random_key;

		$cookie = $_COOKIE['cellularbuys'];
	if (!isset($_COOKIE['cellularbuys'])){ 
	setcookie('cellularbuys', $dealnum, time()+60*60*24*30, "/");
	
		} else {
		
		if ($cookie == "1"){
			$oflag = "sof2";
		} else if ($cookie == "2"){
			$oflag = "sfcart";
		} else {
			$oflag = "sof1";
		}
Now the only way to call the Cookie realtime is with Javascript which is in the ody of HTML

Code: Select all

<script type="text/JavaScript">
<!--

if(document.cookie = "cellularbuys"){
	document.write("it Exists: "+ document.cookie.split("=")[2])
	cookieTst= document.cookie.split("=")[2]
	if(cookieTst == "1"){
		document.write("WE ARE 1")
		oflag=document.write("&o=sof2")
	}else{
		document.write("WE ARE 2")
		oflag=document.write("&o=sfcart")
	}
	
}else{
	document.write("no Cookie Yet")
	oflag=document.write("&o=sof1")
}
	
	

//-->
</script>
Now what i need to do is add the oflag variable on the end of an <a href>

in PHP it looks like this

Code: Select all

<a href="www.xxx.com?r-erwerwe<? echo $oflag; ?>"ckick here </a>
how do i do that in javascript????

Posted: Mon Nov 21, 2005 10:34 am
by Maugrim_The_Reaper
This basically a js question then?

something like below would work...

document.links[0].href = 'newlink';

Adding an ID attribute to the <a> tag would allow link ids, rather than array references...

Posted: Mon Nov 21, 2005 10:56 am
by vincenzobar
ok well i suck at JS, so what would a good link look like and how woulld that work?

and what does your code do? make an array and if so of what?

remember there will be about 3o links to over 1000 files that have to have this variable oflag attached. easy in PHP but PHP doesn't read right away or does someone know a way to make PHP work like this java is working?