help with cookie reading

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vincenzobar
Forum Commoner
Posts: 95
Joined: Wed Nov 02, 2005 9:57 am

help with cookie reading

Post 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????
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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...
vincenzobar
Forum Commoner
Posts: 95
Joined: Wed Nov 02, 2005 9:57 am

Post 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?
Post Reply