Jump to content

sessions and functions


Caitlin-havener
 Share

Recommended Posts

Can anyone see why the value inside my session variables is changing before the session is up (I believe the session should last through the functions)??This is supposed to be a game where two numbers 1-14 are randomly chosen then you bet whether the third number drawn will be between the first two. I need to make the some of the numbers look like A,Q,K,J like a deck of cards while keeping their number value. The first two numbers are supposed to remain the same (stored in the session) when you push "bet." They should come up the same on the next screen but aren't. I've been looking at it so long my mind is boggled, any ideas?

<?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title></title></head><body><form method='post'><?php	$nextaction=$_POST['dowhat'];			$target1=rand(1,14);		$target2=rand(1,14);		//$wincard=rand(1,14);				$maxcard=max($target1,$target2);		$mincard=min($target1,$target2);				$_SESSION['maxcardsess']=$maxcard; 		$_SESSION['mincardsess']=$mincard;						function maxcard_displayfunc(){		$highcard=$_SESSION['maxcardsess'];		switch ($highcard)			{			case 1: 			return $maxcard_display="A";  			break;			case 11:  			return $maxcard_display="J";  			break;			case 12:  			return $maxcard_display="Q";			break;			case 13:  			return $maxcard_display="K";  			break;			default:  			return $maxcard_display=$highcard;			}	}		function mincard_displayfunc(){	$lowcard=$_SESSION['mincardsess'];	switch ($lowcard)			{			case 1: 			return $mincard_display="A";  			break;			case 11:  			return $mincard_display="J";  			break;			case 12:  			return $mincard_display="Q";			break;			case 13:  			return $mincard_display="K";  			break;			default:  			return $mincard_display=$lowcard;			}	}		function wincardfunc($wincard){		switch ($wincard)			{			case 1: 			return $wincard_display="A";  			break;			case 11:  			return $wincard_display="J";  			break;			case 12:  			return $wincard_display="Q";			break;			case 13:  			return $wincard_display="K";  			break;			default:  			return $wincard_display=$wincard;			}	}	//////////////////////////////////////	if (!$nextaction || ($nextaction=="PASS") || ($nextaction=="NEXT DRAW")) 	{								  	/////////////	// SCREEN 1	/////////////		$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();				print "<p>high card=$maxcard_display. low card=$mincard_display.<br />";		print "<input type='submit' name='dowhat' value='BET'>";		print "<input type='submit' name='dowhat' value='PASS'>";	}		else if ($nextaction=="BET")	{		####################		# SCREEN TWO		####################				$wincard=rand(1,14);					$wincard_display=wincardfunc($wincard);				$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();				$maxvalue=$_SESSION['maxcardsess']; 		$maxvalue=$_SESSION['mincardsess'];				print "highcard=$maxcard_display <br/>";		print "target=$wincard_display <br/>";		print "lowcard=$mincard_display <br/>";				if (($wincard<$maxvalue) && ($wincard>$minvalue))		{			print "You win!";		}		else		{			print "You lose!";						}				print "<input type='submit' name='dowhat' value='NEXT DRAW'>";	}	else		print "Error 100: nextaction=$nextaction, but I don't know what to do.";?></form></body></html>

Link to comment
Share on other sites

When I run your code, I get output like this:high card=3. low card=A.(some buttons)target=3lowcard=6You win!(button)and when I var_dump($_SESSION) like I suggested, the $_SESSION array is populated.So what's up?
Where would i put that and what does it do- im unfamilar...
Link to comment
Share on other sites

For example:

function maxcard_displayfunc(){var_dump($_SESSION); // HERE !!!111$highcard=$_SESSION['maxcardsess'];

var_dump displays the contents and their data types of any variable you pass it. A basic debugging tool. Can't live without it.

Link to comment
Share on other sites

For example:
function maxcard_displayfunc(){var_dump($_SESSION); // HERE !!!111$highcard=$_SESSION['maxcardsess'];

var_dump displays the contents and their data types of any variable you pass it. A basic debugging tool. Can't live without it.

I looked at the dump and the session values are changing after I push "bet." I need the high card and low card to be the same after I push "bet." any ideas?
Link to comment
Share on other sites

It looks like you're always generating those values:

		$target1=rand(1,14);		$target2=rand(1,14);		//$wincard=rand(1,14);				$maxcard=max($target1,$target2);		$mincard=min($target1,$target2);				$_SESSION['maxcardsess']=$maxcard; 		$_SESSION['mincardsess']=$mincard;

You'll need to check if they're already set before setting them again, you're changing them every time the page loads. You can just wrap that in an if statement:

if (isset($_SESSION['maxcardsess'])){  $maxcard = $_SESSION['maxcardsess'];  $mincard = $_SESSION['mincardsess'];}else{  $target1=rand(1,14);  $target2=rand(1,14);		  $maxcard=max($target1,$target2);  $mincard=min($target1,$target2);		  $_SESSION['maxcardsess']=$maxcard;   $_SESSION['mincardsess']=$mincard;}

Link to comment
Share on other sites

It looks like you're always generating those values:
		$target1=rand(1,14);		$target2=rand(1,14);		//$wincard=rand(1,14);				$maxcard=max($target1,$target2);		$mincard=min($target1,$target2);				$_SESSION['maxcardsess']=$maxcard; 		$_SESSION['mincardsess']=$mincard;

You'll need to check if they're already set before setting them again, you're changing them every time the page loads. You can just wrap that in an if statement:

if (isset($_SESSION['maxcardsess'])){  $maxcard = $_SESSION['maxcardsess'];  $mincard = $_SESSION['mincardsess'];}else{  $target1=rand(1,14);  $target2=rand(1,14);		  $maxcard=max($target1,$target2);  $mincard=min($target1,$target2);		  $_SESSION['maxcardsess']=$maxcard;   $_SESSION['mincardsess']=$mincard;}

wow that was a problem solved quickly. Thanks!
Link to comment
Share on other sites

Having another issue with some code that I added to the prior program. When the maxcard or mincard are an ace, the value is already a 1 OR a 14. I want the value of ace to change to 1 or 14 depending on whichever one has a better chance of winning the bet (the difference between the cards are greater, thus a better chance of target card falling in between the two). I am having a problem with the session values again apparently as when dumping the values they are changing right before the nested 'if' statements as noted in the code. I can't find the issue, can you spot it? The problem is in between the comments "here is the issue."

<?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title></title><link rel="stylesheet" type="text/css" href="style.css" /></head><body><div class="roundedBox">	<div class="top"><div class="bottom">	<div class="left"><div class="right">	<div class="topLeft"><div class="topRight">	<div class="bottomLeft"><div class="bottomRight"><div class="boxContent"><div id="content"><form method='post'><?php	$nextaction=$_POST['dowhat'];									function maxcard_displayfunc(){//var_dump($_SESSION);		$highcard=$_SESSION['maxcardsess'];		switch ($highcard)			{			case 1 || 14: 			return $maxcard_display="A";  			break;			case 11:  			return $maxcard_display="J";  			break;			case 12:  			return $maxcard_display="Q";			break;			case 13:  			return $maxcard_display="K";  			break;			default:  			return $maxcard_display=$highcard;			}	}		function mincard_displayfunc(){	//	var_dump($_SESSION);	$lowcard=$_SESSION['mincardsess'];	switch ($lowcard)			{			case 1 || 14: 			return $mincard_display="A";  			break;			case 11:  			return $mincard_display="J";  			break;			case 12:  			return $mincard_display="Q";			break;			case 13:  			return $mincard_display="K";  			break;			default:  			return $mincard_display=$lowcard;			}	}		function wincardfunc($wincard){		switch ($wincard)			{			case 1 || 14: 			return $wincard_display="A";  			break;			case 11:  			return $wincard_display="J";  			break;			case 12:  			return $wincard_display="Q";			break;			case 13:  			return $wincard_display="K";  			break;			default:  			return $wincard_display=$wincard;			}	}	//////////////////////////////////////	if (!$nextaction || ($nextaction=="PASS") || ($nextaction=="NEXT DRAW")) 	{								  	#################	## SCREEN 1	#################		$target1=rand(1,14);		$target2=rand(1,14);		//$wincard=rand(1,14);				$maxcard=max($target1,$target2);		$mincard=min($target1,$target2);				$_SESSION['maxcardsess']=$maxcard; 		$_SESSION['mincardsess']=$mincard;		$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();						////////////////////////////////////////////////////////		//  If card is an ace, change value of ace to 1 or 14, 		//  whichever is more favorable to user. 		////////////////////////////////////////////////////////		print "var dump before maxcard if statement:";		var_dump($_SESSION);		///////////something wrong with this  (below)///				if($maxcard_display=="A"){			$othercard=$_SESSION['mincardsess'];						print "var dump before nested maxcard if statements:";			var_dump($_SESSION);						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";}			else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";}}				///////////something wrong with this ^///			print "var dump before mincard if statement:";		    var_dump($_SESSION);				if($mincard_display=="A"){			$othercard=$_SESSION['maxcardsess'];						print "var dump before nested maxcard if statements:";			var_dump($_SESSION);						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";}			else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";}}										print "<p>high card=$maxcard_display. low card=$mincard_display.<br />";		print "<input type='submit' name='dowhat' value='BET'>";		print "<input type='submit' name='dowhat' value='PASS'>";	}		else if ($nextaction=="BET")	{		####################		# SCREEN TWO		####################				$wincard=rand(1,14);					$wincard_display=wincardfunc($wincard);				$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();				$maxvalue=$_SESSION['maxcardsess']; 		$minvalue=$_SESSION['mincardsess'];				print "highcard=$maxcard_display <br/>";		print "target=$wincard_display <br/>";		print "lowcard=$mincard_display <br/>";				if (($wincard<$maxvalue) && ($wincard>$minvalue))		{			print "You win!";		}		else		{			print "You lose!";						}				print "<input type='submit' name='dowhat' value='NEXT DRAW'>";	}	else		print "Error 100: nextaction=$nextaction, but I don't know what to do.";?></form></div></div>	</div></div></div></div></div></div></div></div></div></body></html>

Link to comment
Share on other sites

I'm not exactly sure if that's the reason for the particular problem, but it seems like something to cause trouble so...

case 1 || 14:

"1 || 14" is going to return a boolean value. That value in turn is going to be compared to whatever is in the switch. Since it's a loose comparrison, this essentially means this is only going to match 1, but not 14. If you want the code below this to execute in either case, you should have two separate case statements below each other, like:

case 1:code 14:

Fix this in all places, and see if it helps.

Link to comment
Share on other sites

I'm not exactly sure if that's the reason for the particular problem, but it seems like something to cause trouble so...
case 1 || 14:

"1 || 14" is going to return a boolean value. That value in turn is going to be compared to whatever is in the switch. Since it's a loose comparrison, this essentially means this is only going to match 1, but not 14. If you want the code below this to execute in either case, you should have two separate case statements below each other, like:

case 1:code 14:

Fix this in all places, and see if it helps.

Yep! Sure did thanks!
Link to comment
Share on other sites

Why isn't this going to screen two when I press "bet"?!

<?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title></title><link rel="stylesheet" type="text/css" href="style.css" /></head><body><div class="roundedBox">	<div class="top"><div class="bottom">	<div class="left"><div class="right">	<div class="topLeft"><div class="topRight">	<div class="bottomLeft"><div class="bottomRight"><div class="boxContent"><div id="content"><form method='post'><?php	$nextaction=$_POST['dowhat'];								function maxcard_displayfunc(){//var_dump($_SESSION);		$highcard=$_SESSION['maxcardsess'];		switch ($highcard)			{			case 1: 			return $maxcard_display="A";  			break;			case 14: 			return $maxcard_display="A";  			break;			case 11:  			return $maxcard_display="J";  			break;			case 12:  			return $maxcard_display="Q";			break;			case 13:  			return $maxcard_display="K";  			break;			default:  			return $maxcard_display=$highcard;			}	}		function mincard_displayfunc(){	//	var_dump($_SESSION);	$lowcard=$_SESSION['mincardsess'];	switch ($lowcard)			{			case 1: 			return $mincard_display="A";  			break;			case 11:  			return $mincard_display="J";  			break;			case 12:  			return $mincard_display="Q";			break;			case 13:  			return $mincard_display="K";  			break;			case 14: 			return $maxcard_display="A";  			break;			default:  			return $mincard_display=$lowcard;			}	}		function wincardfunc($wincard){		switch ($wincard)			{			case 1: 			return $wincard_display="A";  			break;			case 11:  			return $wincard_display="J";  			break;			case 12:  			return $wincard_display="Q";			break;			case 13:  			return $wincard_display="K";  			break;			case 14: 			return $maxcard_display="A";  			break;			default:  			return $wincard_display=$wincard;			}	}		maincontent();function maincontent(){	if (!$nextaction || ($nextaction=="PASS") || ($nextaction=="NEXT DRAW")) 	{								  	#################	## SCREEN 1	#################		$target1=rand(1,14);		$target2=rand(1,14);		//$wincard=rand(1,14);				$maxcard=max($target1,$target2);		$mincard=min($target1,$target2);				$_SESSION['maxcardsess']=$maxcard; 		$_SESSION['mincardsess']=$mincard;		$maxcard_value=$_SESSION['maxcardsess'];		$mincard_value=$_SESSION['mincardsess'];								//change the way value is displayed (to look like a card J,K,Q,A)		$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();						////////////////////////////////////////////////////////		//  If card is an ace, change value of ace to 1 or 14, 		//  whichever is more favorable to user. 		////////////////////////////////////////////////////////				if($maxcard_display=="A"){			$othercard=$_SESSION['mincardsess'];						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";}			else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";}}						else if($mincard_display=="A"){			$othercard=$_SESSION['maxcardsess'];						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";}			else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";}}									////////////////////////////////////////////////////////		//  If cards are too close in value, generate new set 		////////////////////////////////////////////////////////		if(($maxcard_value-$mincard_value==0) || ($maxcard_value-$mincard_value==1)){			maincontent();}		else{		print "<p>high card=$maxcard_display. low card=$mincard_display.<br />";		print "<input type='submit' name='dowhat' value='BET'>";		print "<input type='submit' name='dowhat' value='PASS'>";}		}		else if ($nextaction=="BET")	{		####################		# SCREEN TWO		####################				$wincard=rand(1,14);					$wincard_display=wincardfunc($wincard);				$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();				$maxvalue=$_SESSION['maxcardsess']; 		$minvalue=$_SESSION['mincardsess'];				print "highcard=$maxcard_display <br/>";		print "target=$wincard_display <br/>";		print "lowcard=$mincard_display <br/>";				if (($wincard<$maxvalue) && ($wincard>$minvalue))		{			print "You win!";		}		else		{			print "You lose!";						}				print "<input type='submit' name='dowhat' value='NEXT DRAW'>";	}	else		print "Error 100: nextaction=$nextaction, but I don't know what to do.";}?></form></div></div>	</div></div></div></div></div></div></div></div></div></body></html>

Link to comment
Share on other sites

Try to indent all of your PHP code properly. Right now, the style you have isn't exactly clear as to where each code block starts and ends.I suggest using the K&R style, tailored for PHP, like:

statement;if (condition) {	statement;	if (nestedCondition) {		statement;	}elseif(condition) {		statement;	}else {		statement;	}}else {	statement;}

(and add block delimiters even around one liners like the last print)Doing just that is likely to reveal some sort of bracket mismatch (where you end a section earlier or later than you think you are).

Link to comment
Share on other sites

Try to indent all of your PHP code properly. Right now, the style you have isn't exactly clear as to where each code block starts and ends.I suggest using the K&R style, tailored for PHP, like:
<?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title></title><link rel="stylesheet" type="text/css" href="style.css" /></head><body><div class="roundedBox">	<div class="top"><div class="bottom">	<div class="left"><div class="right">	<div class="topLeft"><div class="topRight">	<div class="bottomLeft"><div class="bottomRight"><div class="boxContent"><div id="content"><form method='post'><?php	$nextaction=$_POST['dowhat'];								function maxcard_displayfunc(){//var_dump($_SESSION);		$highcard=$_SESSION['maxcardsess'];		switch ($highcard)			{			case 1: 			return $maxcard_display="A";  			break;			case 14: 			return $maxcard_display="A";  			break;			case 11:  			return $maxcard_display="J";  			break;			case 12:  			return $maxcard_display="Q";			break;			case 13:  			return $maxcard_display="K";  			break;			default:  			return $maxcard_display=$highcard;			}	}		function mincard_displayfunc(){	//	var_dump($_SESSION);	$lowcard=$_SESSION['mincardsess'];	switch ($lowcard)			{			case 1: 			return $mincard_display="A";  			break;			case 11:  			return $mincard_display="J";  			break;			case 12:  			return $mincard_display="Q";			break;			case 13:  			return $mincard_display="K";  			break;			case 14: 			return $maxcard_display="A";  			break;			default:  			return $mincard_display=$lowcard;			}	}		function wincardfunc($wincard){		switch ($wincard)			{			case 1: 			return $wincard_display="A";  			break;			case 11:  			return $wincard_display="J";  			break;			case 12:  			return $wincard_display="Q";			break;			case 13:  			return $wincard_display="K";  			break;			case 14: 			return $maxcard_display="A";  			break;			default:  			return $wincard_display=$wincard;			}	}		maincontent();function maincontent(){	if (!$nextaction || ($nextaction=="PASS") || ($nextaction=="NEXT DRAW")) 	{								  	#################	## SCREEN 1	#################		$target1=rand(1,14);		$target2=rand(1,14);		//$wincard=rand(1,14);				$maxcard=max($target1,$target2);		$mincard=min($target1,$target2);				$_SESSION['maxcardsess']=$maxcard; 		$_SESSION['mincardsess']=$mincard;		$maxcard_value=$_SESSION['maxcardsess'];		$mincard_value=$_SESSION['mincardsess'];								//change the way value is displayed (to look like a card J,K,Q,A)		$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();						////////////////////////////////////////////////////////		//  If card is an ace, change value of ace to 1 or 14, 		//  whichever is more favorable to user. 		////////////////////////////////////////////////////////				if($maxcard_display=="A"){			$othercard=$_SESSION['mincardsess'];						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";			}else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";			}				}else if($mincard_display=="A"){			$othercard=$_SESSION['maxcardsess'];						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";			}			else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";		}}				///			    /////////////////////////////////////////////////////		//  If cards are too close in value, generate new set 		////////////////////////////////////////////////////////		if(($maxcard_value-$mincard_value==0) || ($maxcard_value-$mincard_value==1)){			maincontent();		}else{		print "<p>high card=$maxcard_display. low card=$mincard_display.<br />";		print "<input type='submit' name='dowhat' value='BET'>";		print "<input type='submit' name='dowhat' value='PASS'>";		}				}else if ($nextaction=="BET")	{		####################		# SCREEN TWO		####################				$wincard=rand(1,14);					$wincard_display=wincardfunc($wincard);				$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();				$maxvalue=$_SESSION['maxcardsess']; 		$minvalue=$_SESSION['mincardsess'];				print "highcard=$maxcard_display <br/>";		print "target=$wincard_display <br/>";		print "lowcard=$mincard_display <br/>";				if (($wincard<$maxvalue) && ($wincard>$minvalue))		{			print "You win!";				}else{			print "You lose!";						}				print "<input type='submit' name='dowhat' value='NEXT DRAW'>";		}else{		print "Error 100: nextaction=$nextaction, but I don't know what to do.";	}}?></form></div></div>	</div></div></div></div></div></div></div></div></div></body></html>

Link to comment
Share on other sites

I don't really see a change from your previous code, but anyway, upon doing some proper formatting myself (using NetBeans' "Format" option), I saw the problem... it's that you're having the whole thing inside a function, but the $nextaction variable is outside of a function.In PHP, unlike many other languages, variables are available only in the scope they're declared - they are not available in inner scopes. A new scope is defined by each function, plus the one in the global scope. You can import a variable from the global scope into a function scope by adding "global $nameOfTheVariable" somewhere in the function.BTW, if you turn on warnings, you'll see a warning initially due to the $_POST['dowhat'] being undefined. It's best to manually check for its existance and set a default value.Here's a solution, with the suggestion implemented (I'm setting the default value to an empty string in this case; see Ternary Operator if this construct is new for you) and formatted in the way I had in mind:

<?phpsession_start();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />        <title></title>        <link rel="stylesheet" type="text/css" href="style.css" />    </head>    <body>        <div class="roundedBox">            <div class="top"><div class="bottom"><div class="left"><div class="right"><div class="topLeft"><div class="topRight"><div class="bottomLeft"><div class="bottomRight">                                            <div class="boxContent">                                                <div id="content">                                                    <form method='post'>                                                        <?php                                                        $nextaction = isset($_POST['dowhat']) ? $_POST['dowhat'] : '';                                                        function maxcard_displayfunc() {                                                            //var_dump($_SESSION);                                                            $highcard = $_SESSION['maxcardsess'];                                                            switch ($highcard) {                                                                case 1:                                                                    return $maxcard_display = "A";                                                                    break;                                                                case 14:                                                                    return $maxcard_display = "A";                                                                    break;                                                                case 11:                                                                    return $maxcard_display = "J";                                                                    break;                                                                case 12:                                                                    return $maxcard_display = "Q";                                                                    break;                                                                case 13:                                                                    return $maxcard_display = "K";                                                                    break;                                                                default:                                                                    return $maxcard_display = $highcard;                                                            }                                                        }                                                        function mincard_displayfunc() {                                                            //	var_dump($_SESSION);                                                            $lowcard = $_SESSION['mincardsess'];                                                            switch ($lowcard) {                                                                case 1:                                                                    return $mincard_display = "A";                                                                    break;                                                                case 11:                                                                    return $mincard_display = "J";                                                                    break;                                                                case 12:                                                                    return $mincard_display = "Q";                                                                    break;                                                                case 13:                                                                    return $mincard_display = "K";                                                                    break;                                                                case 14:                                                                    return $maxcard_display = "A";                                                                    break;                                                                default:                                                                    return $mincard_display = $lowcard;                                                            }                                                        }                                                        function wincardfunc($wincard) {                                                            switch ($wincard) {                                                                case 1:                                                                    return $wincard_display = "A";                                                                    break;                                                                case 11:                                                                    return $wincard_display = "J";                                                                    break;                                                                case 12:                                                                    return $wincard_display = "Q";                                                                    break;                                                                case 13:                                                                    return $wincard_display = "K";                                                                    break;                                                                case 14:                                                                    return $maxcard_display = "A";                                                                    break;                                                                default:                                                                    return $wincard_display = $wincard;                                                            }                                                        }                                                        maincontent();                                                        function maincontent() {                                                            global $nextaction;                                                            if (!$nextaction || ($nextaction == "PASS") || ($nextaction == "NEXT DRAW")) {                                                                #################                                                                ## SCREEN 1                                                                #################                                                                $target1 = rand(1, 14);                                                                $target2 = rand(1, 14);                                                                //$wincard=rand(1,14);                                                                $maxcard = max($target1, $target2);                                                                $mincard = min($target1, $target2);                                                                $_SESSION['maxcardsess'] = $maxcard;                                                                $_SESSION['mincardsess'] = $mincard;                                                                $maxcard_value = $_SESSION['maxcardsess'];                                                                $mincard_value = $_SESSION['mincardsess'];                                                                //change the way value is displayed (to look like a card J,K,Q,A)                                                                $maxcard_display = maxcard_displayfunc();                                                                $mincard_display = mincard_displayfunc();                                                                ////////////////////////////////////////////////////////                                                                //  If card is an ace, change value of ace to 1 or 14,                                                                //  whichever is more favorable to user.                                                                ////////////////////////////////////////////////////////                                                                if ($maxcard_display == "A") {                                                                    $othercard = $_SESSION['mincardsess'];                                                                    if ($othercard - 1 > 14 - $othercard) {                                                                        $acecard = 1;                                                                        $_SESSION['maxcardsess'] = max($othercard, $acecard);                                                                        $_SESSION['mincardsess'] = min($othercard, $acecard);                                                                        print "</br>Ace will have a value of $acecard, because it favors your bet.";                                                                    }else {                                                                        $acecard = 14;                                                                        $_SESSION['maxcardsess'] = max($othercard, $acecard);                                                                        $_SESSION['mincardsess'] = min($othercard, $acecard);                                                                        print "</br>Ace will have a value of $acecard, because it favors your bet.";                                                                    }                                                                }else if ($mincard_display == "A") {                                                                    $othercard = $_SESSION['maxcardsess'];                                                                    if ($othercard - 1 > 14 - $othercard) {                                                                        $acecard = 1;                                                                        $_SESSION['maxcardsess'] = max($othercard, $acecard);                                                                        $_SESSION['mincardsess'] = min($othercard, $acecard);                                                                        print "</br>Ace will have a value of $acecard, because it favors your bet.";                                                                    }else {                                                                        $acecard = 14;                                                                        $_SESSION['maxcardsess'] = max($othercard, $acecard);                                                                        $_SESSION['mincardsess'] = min($othercard, $acecard);                                                                        print "</br>Ace will have a value of $acecard, because it favors your bet.";                                                                    }                                                                }                                                                ///                                                                /////////////////////////////////////////////////////                                                                //  If cards are too close in value, generate new set                                                                ////////////////////////////////////////////////////////                                                                if (($maxcard_value - $mincard_value == 0) || ($maxcard_value - $mincard_value == 1)) {                                                                    maincontent();                                                                }else {                                                                    print "<p>high card=$maxcard_display. low card=$mincard_display.<br />";                                                                    print "<input type='submit' name='dowhat' value='BET'>";                                                                    print "<input type='submit' name='dowhat' value='PASS'>";                                                                }                                                            }elseif ($nextaction == "BET") {                                                                ####################                                                                # SCREEN TWO                                                                ####################                                                                $wincard = rand(1, 14);                                                                $wincard_display = wincardfunc($wincard);                                                                $maxcard_display = maxcard_displayfunc();                                                                $mincard_display = mincard_displayfunc();                                                                $maxvalue = $_SESSION['maxcardsess'];                                                                $minvalue = $_SESSION['mincardsess'];                                                                print "highcard=$maxcard_display <br/>";                                                                print "target=$wincard_display <br/>";                                                                print "lowcard=$mincard_display <br/>";                                                                if (($wincard < $maxvalue) && ($wincard > $minvalue)) {                                                                    print "You win!";                                                                }else {                                                                    print "You lose!";                                                                }                                                                print "<input type='submit' name='dowhat' value='NEXT DRAW'>";                                                            }else {                                                                print "Error 100: nextaction=$nextaction, but I don't know what to do.";                                                            }                                                        }                                                        ?>                                                    </form>                                                </div>                                            </div>                                        </div></div></div></div></div></div></div></div>        </div>    </body></html>

Link to comment
Share on other sites

I guess I didn't really understand what you were saying with the formatting. Yeah, I'm still getting used to the whole global variable thing but see what you are doing now. What is "$nextaction = isset($_POST['dowhat']) ? $_POST['dowhat'] : '' doing after the "?" mark?

Link to comment
Share on other sites

It's a shorthand if/else assignment statement. This line:

$nextaction = isset($_POST['dowhat']) ? $_POST['dowhat'] : '';

is equivalent to this:

if (isset($_POST['dowhat']))  $nextaction = $_POST['dowhat'];else  $nextaction = '';

The first part of the statement is the condition to check, then after "?" it's the value to return if the condition was true, and after ":" is the value to return if the condition was false.

Link to comment
Share on other sites

It's a shorthand if/else assignment statement. This line:
<?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title></title><link rel="stylesheet" type="text/css" href="style.css" /></head><body><div class="roundedBox">	<div class="top"><div class="bottom">	<div class="left"><div class="right">	<div class="topLeft"><div class="topRight">	<div class="bottomLeft"><div class="bottomRight"><div class="boxContent"><div id="content"><form method='post'><?php	$nextaction = isset($_POST['dowhat']) ? $_POST['dowhat'] : '';								function maxcard_displayfunc(){//var_dump($_SESSION);		$highcard=$_SESSION['maxcardsess'];		switch ($highcard)			{			case 1: 			return $maxcard_display="A";  			break;			case 14: 			return $maxcard_display="A";  			break;			case 11:  			return $maxcard_display="J";  			break;			case 12:  			return $maxcard_display="Q";			break;			case 13:  			return $maxcard_display="K";  			break;			default:  			return $maxcard_display=$highcard;			}	}		function mincard_displayfunc(){	//	var_dump($_SESSION);	$lowcard=$_SESSION['mincardsess'];	switch ($lowcard)			{			case 1: 			return $mincard_display="A";  			break;			case 11:  			return $mincard_display="J";  			break;			case 12:  			return $mincard_display="Q";			break;			case 13:  			return $mincard_display="K";  			break;			case 14: 			return $maxcard_display="A";  			break;			default:  			return $mincard_display=$lowcard;			}	}		function wincardfunc($wincard){		switch ($wincard)			{			case 1: 			return $wincard_display="A";  			break;			case 11:  			return $wincard_display="J";  			break;			case 12:  			return $wincard_display="Q";			break;			case 13:  			return $wincard_display="K";  			break;			case 14: 			return $maxcard_display="A";  			break;			default:  			return $wincard_display=$wincard;			}	}function whosturn(){	if(isset($_SESSION['turnsess']) || $_SESSION['turnsess']=="gold")	{		return $_SESSION['turnsess']="black";	}	else 	{		return $_SESSION['turnsess']="gold";	}}maincontent();/*while (turn=="black"){	global $nextaction;		if ($nextaction=="PASS" || $nextaction=="NEXT DRAW"){		$turn="gold";	}	else{		maincontent();	}while (turn=="gold"){	global $nextaction;		execute code;	if ($nextaction=="PASS" || $nextaction=="NEXT DRAW"){		$turn="black";	}	else{		maincontent();	}*/	function maincontent(){	global $nextaction;	if (!$nextaction || ($nextaction=="PASS") || ($nextaction=="NEXT DRAW")) 	{				/*global $turn;		if($turn=="black")		   {			 $turn="gold";		   }		else		 {			 $turn="black";		 }*/	#################	## SCREEN 1	#################		$turn=whosturn();		print "It is $turn team's turn. <br />";		$target1=rand(1,14);		$target2=rand(1,14);		//$wincard=rand(1,14);				$maxcard=max($target1,$target2);		$mincard=min($target1,$target2);				$_SESSION['maxcardsess']=$maxcard; 		$_SESSION['mincardsess']=$mincard;		$maxcard_value=$_SESSION['maxcardsess'];		$mincard_value=$_SESSION['mincardsess'];								//change the way value is displayed (to look like a card J,K,Q,A)		$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();						////////////////////////////////////////////////////////		//  If card is an ace, change value of ace to 1 or 14, 		//  whichever is more favorable to user. 		////////////////////////////////////////////////////////				if($maxcard_display=="A"){			$othercard=$_SESSION['mincardsess'];						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";			}else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";			}				}else if($mincard_display=="A"){			$othercard=$_SESSION['maxcardsess'];						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";			}			else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";		}}				///			    /////////////////////////////////////////////////////		//  If cards are too close in value, generate new set 		////////////////////////////////////////////////////////		if(($maxcard_value-$mincard_value==0) || ($maxcard_value-$mincard_value==1)){			maincontent();		}else{		print "<p>high card=$maxcard_display. low card=$mincard_display.<br />";		print "<input type='submit' name='dowhat' value='BET'>";		print "<input type='submit' name='dowhat' value='PASS'>";		}				}else if ($nextaction=="BET")	{		####################		# SCREEN TWO		####################				print "It is $turn team's turn. <br />";		$wincard=rand(1,14);					$wincard_display=wincardfunc($wincard);				$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();				$maxvalue=$_SESSION['maxcardsess']; 		$minvalue=$_SESSION['mincardsess'];				print "highcard=$maxcard_display <br/>";		print "target=$wincard_display <br/>";		print "lowcard=$mincard_display <br/>";				if (($wincard<$maxvalue) && ($wincard>$minvalue))		{			print "You win!";				}else{			print "You lose!";						}				print "<input type='submit' name='dowhat' value='NEXT DRAW'>";		}else{		print "Error 100: nextaction=$nextaction, but I don't know what to do.";	}}?></form></div></div>	</div></div></div></div></div></div></div></div></div></body></html>

Link to comment
Share on other sites

What happens when you run that?
This program is a card game where there are two random values generated (2-14), then you bet or pass on whether you think the third generated value will fall in between the first two values. They are shown as graphics of cards 2-10 and J,Q, K, A(value of 1 or 14). CURRENT TASK: I need to make the game have two teams- a black team and gold team. The first screen with the two generated values should display "black team's turn" and it will still be their turn if the "bet" button is pushed but if they push "pass" then "gold team's turn" will display. (I'm going to need to come up with a way to keep score of each team later)
Link to comment
Share on other sites

It's this part:

function whosturn(){if(isset($_SESSION['turnsess']) || $_SESSION['turnsess']=="gold"){return $_SESSION['turnsess']="black";}else{return $_SESSION['turnsess']="gold";}}

Full code:

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><!--    Author: Caitlin Havener	   Date: 10/19/10  --><link rel="stylesheet" type="text/css" href="style.css" /><title>Wine of the Week Club</title></head><!--Header, navigation, and main page image created by Caitlin Havener with open source flickr.com images --><body><div class="roundedBox">	<div class="top"><div class="bottom">	<div class="left"><div class="right">	<div class="topLeft"><div class="topRight">	<div class="bottomLeft"><div class="bottomRight"><div class="boxContent"><!--START MAIN CONTENT--><div id="main">	<div id="header">		<img src="images/grapes_01.jpg" alt="Wine of the Week Club" />	</div>	<div id="navigation">		<img id="nav" src="images/grapes_02.jpg" alt="links" usemap="#nav_map" />		<map id="nav_map" name="nav_map">			<area shape="poly" coords="11,112,110,75,122,144,23,145"			href="index.htm" alt="Home" />			<area shape="poly" coords="8,178,116,137,121,171,20,212"			href="ourwines.htm" alt="Our Wines" />			<area shape="poly" coords="9,252,111,211,124,245,21,286"			href="benefits.htm" alt="Benefits" />			<area shape="poly" coords="10,317,113,279,122,320,19,359"			href="join.htm" alt="Join" />		</map>	</div>	<div id="content">		<img id="main_img" src="images/mainimg.jpg" alt="main" usemap="#main_map" />		<map id="main_map" name="main_map">			<area shape="rect" coords="243,194,381,334"			href="join.htm" alt="Join" />		</map>	</div>		<div id="footer">		<p>Website made by <a href="mailto:caitlin-havener@hotmail.com?Subject=Web%20Design%20Inquiry"> Caitlin Havener.</a></p>	</div></div><!--END MAIN CONTENT--></div>	</div></div></div></div></div></div></div></div></div></body></html>

Link to comment
Share on other sites

There's only HTML in that last "full code" example.... I'll assume your real full code is the previous one.... there are a lot of commented sections in it. Maybe some of them have what you want.You should seriously consider enabling error display so that you can see some of the wrongs yourself. The easiest way to do that is to add the following in your PHP file, right before session_start():

error_reporting(E_ALL | E_STRICT);ini_set('display_errors', 'On');

The error I see with your script when I bet is that $turn is undefined, and indeed, it isn't... it was defined... sort of... in your commented parts.

Link to comment
Share on other sites

Later in the code, I try to define $turn by "$turn=whosturn()." I want turn to be defined by the following function:

function whosturn(){	if(isset($_SESSION['turnsess']) || $_SESSION['turnsess']=="gold")	{		return $_SESSION['turnsess']="black";	}	else 	{		return $_SESSION['turnsess']="gold";	}}

I don't get why it doesn't work, but I'm new to using the "isset" function. Do you see whats wrong here? Some of my other attempts are commented out. I posted the wrong code prior meant to put the following:

<?phperror_reporting(E_ALL | E_STRICT);ini_set('display_errors', 'On'); session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title></title><link rel="stylesheet" type="text/css" href="style.css" /></head><body><div class="roundedBox">	<div class="top"><div class="bottom">	<div class="left"><div class="right">	<div class="topLeft"><div class="topRight">	<div class="bottomLeft"><div class="bottomRight"><div class="boxContent"><div id="content"><form method='post'><?php	$nextaction = isset($_POST['dowhat']) ? $_POST['dowhat'] : '';								function maxcard_displayfunc(){//var_dump($_SESSION);		$highcard=$_SESSION['maxcardsess'];		switch ($highcard)			{			case 1: 			return $maxcard_display="<img class='card_display' src='images/A.jpg' alt=' ' />";  			break;			case 2: 			return $maxcard_display="<img class='card_display' src='images/2.jpg' alt=' ' />";  			break;			case 3: 			return $maxcard_display="<img class='card_display' src='images/3.jpg' alt=' ' />";  			break;			case 4: 			return $maxcard_display="<img class='card_display' src='images/4.jpg' alt=' ' />";  			break;			case 5: 			return $maxcard_display="<img class='card_display' src='images/5.jpg' alt=' ' />";  			break;			case 6: 			return $maxcard_display="<img class='card_display' src='images/6.jpg' alt=' ' />";  			break;			case 7: 			return $maxcard_display="<img class='card_display' src='images/7.jpg' alt=' ' />";  			break;			case 8: 			return $maxcard_display="<img class='card_display' src='images/8.jpg' alt=' ' />";  			break;			case 9: 			return $maxcard_display="<img class='card_display' src='images/9.jpg' alt=' ' />";  			break;			case 10: 			return $maxcard_display="<img class='card_display' src='images/10.jpg' alt=' ' />";  			break;			case 14: 			return $maxcard_display="<img class='card_display' src='images/A.jpg' alt=' ' />";  			break;			case 11:  			return $maxcard_display="<img class='card_display' src='images/J.jpg' alt=' ' />";  			break;			case 12:  			return $maxcard_display="<img class='card_display' src='images/Q.jpg' alt=' ' />";			break;			case 13:  			return $maxcard_display="<img class='card_display' src='images/K.jpg' alt=' ' />";  			break;			default:  			return $maxcard_display=$highcard;			}	}		function mincard_displayfunc(){	//	var_dump($_SESSION);	$lowcard=$_SESSION['mincardsess'];	switch ($lowcard)			{			case 1: 			return $mincard_display="<img class='card_display' src='images/A.jpg' alt=' ' />";  			break;			case 2: 			return $mincard_display="<img class='card_display' src='images/2.jpg' alt=' ' />";  			break;			case 3: 			return $mincard_display="<img class='card_display' src='images/3.jpg' alt=' ' />";  			break;			case 4: 			return $mincard_display="<img class='card_display' src='images/4.jpg' alt=' ' />";  			break;			case 5: 			return $mincard_display="<img class='card_display' src='images/5.jpg' alt=' ' />";  			break;			case 6: 			return $mincard_display="<img class='card_display' src='images/6.jpg' alt=' ' />";  			break;			case 7: 			return $mincard_display="<img class='card_display' src='images/7.jpg' alt=' ' />";  			break;			case 8: 			return $mincard_display="<img class='card_display' src='images/8.jpg' alt=' ' />";  			break;			case 9: 			return $mincard_display="<img class='card_display' src='images/9.jpg' alt=' ' />";  			break;			case 10: 			return $mincard_display="<img class='card_display' src='images/10.jpg' alt=' ' />";  			break;			case 11:  			return $mincard_display="<img class='card_display' src='images/J.jpg' alt=' ' />";  			break;			case 12:  			return $mincard_display="<img class='card_display' src='images/Q.jpg' alt=' ' />";			break;			case 13:  			return $mincard_display="<img class='card_display' src='images/K.jpg' alt=' ' />";;  			break;			case 14: 			return $mincard_display="<img class='card_display' src='images/A.jpg' alt=' ' />";  			break;			default:  			return $mincard_display=$lowcard;			}	}		function wincardfunc($wincard){		switch ($wincard)			{			case 1: 			return $wincard_display="<img class='card_display' src='images/A.jpg' alt=' ' />";  			break;			case 2: 			return $wincard_display="<img class='card_display' src='images/2.jpg' alt=' ' />";  			break;			case 3: 			return $wincard_display="<img class='card_display' src='images/3.jpg' alt=' ' />";  			break;			case 4: 			return $wincard_display="<img class='card_display' src='images/4.jpg' alt=' ' />";  			break;			case 5: 			return $wincard_display="<img class='card_display' src='images/5.jpg' alt=' ' />";  			break;			case 6: 			return $wincard_display="<img class='card_display' src='images/6.jpg' alt=' ' />";  			break;			case 7: 			return $wincard_display="<img class='card_display' src='images/7.jpg' alt=' ' />";  			break;			case 8: 			return $wincard_display="<img class='card_display' src='images/8.jpg' alt=' ' />";  			break;			case 9: 			return $wincard_display="<img class='card_display' src='images/9.jpg' alt=' ' />";  			break;			case 10: 			return $wincard_display="<img class='card_display' src='images/10.jpg' alt=' ' />";  			break;			case 11:  			return $wincard_display="<img class='card_display' src='images/J.jpg' alt=' ' />";  			break;			case 12:  			return $wincard_display="<img class='card_display' src='images/Q.jpg' alt=' ' />";			break;			case 13:  			return $wincard_display="<img class='card_display' src='images/K.jpg' alt=' ' />";  			break;			case 14: 			return $wincard_display="<img class='card_display' src='images/A.jpg' alt=' ' />";  			break;			default:  			return $wincard_display=$wincard;			}	}function whosturn(){	if(isset($_SESSION['turnsess']) || $_SESSION['turnsess']=="gold")	{		return $_SESSION['turnsess']="black";	}	else 	{		return $_SESSION['turnsess']="gold";	}}print"<h1 id='header'>Acey-Ducey</h1>";maincontent();print "<div class='right_side'><h2>Score:</h2><br/><h3 class='black'>Black</h3><br/><h3 class='gold'>Gold</h3><br/><em><b>Directions:</b></em></div>";/*while (turn=="black"){	global $nextaction;		if ($nextaction=="PASS" || $nextaction=="NEXT DRAW"){		$turn="gold";	}	else{		maincontent();	}while (turn=="gold"){	global $nextaction;		execute code;	if ($nextaction=="PASS" || $nextaction=="NEXT DRAW"){		$turn="black";	}	else{		maincontent();	}*/	function maincontent(){	global $nextaction;	if (!$nextaction || ($nextaction=="PASS") || ($nextaction=="NEXT DRAW")) 	{				/*global $turn;		if($turn=="black")		   {			 $turn="gold";		   }		else		 {			 $turn="black";		 }*/	#################	## SCREEN 1	#################	##  !! Extra Features: Graphical cards, limited range				$turn=whosturn();		print "<div class='right_side'><h2>It is $turn team's turn.</h2> <br /></div>";		$target1=rand(2,14);		$target2=rand(2,14);		//$wincard=rand(1,14);				$maxcard=max($target1,$target2);		$mincard=min($target1,$target2);				$_SESSION['maxcardsess']=$maxcard; 		$_SESSION['mincardsess']=$mincard;		$maxcard_value=$_SESSION['maxcardsess'];		$mincard_value=$_SESSION['mincardsess'];								//change the way value is displayed (to look like a card J,K,Q,A)		$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();						////////////////////////////////////////////////////////		//  If card is an ace, change value of ace to 1 or 14, 		//  whichever is more favorable to user. 		////////////////////////////////////////////////////////				if($maxcard_display=="A"){			$othercard=$_SESSION['mincardsess'];						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";			}else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";			}				}else if($mincard_display=="A"){			$othercard=$_SESSION['maxcardsess'];						if($othercard-1 > 14-$othercard){				$acecard=1;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";			}			else{				$acecard=14;				$_SESSION['maxcardsess']=max($othercard,$acecard);				$_SESSION['mincardsess']=min($othercard,$acecard);				print "</br>Ace will have a value of $acecard, because it favors your bet.";		}}				///			    /////////////////////////////////////////////////////		//  If cards are too close in value, generate new set 		////////////////////////////////////////////////////////		if(($maxcard_value-$mincard_value==0) || ($maxcard_value-$mincard_value==1)){			maincontent();		}else{		print "<div class='cards'><div class='cardboxes'>high card=<br/>$maxcard_display </div>";		print "<div class='cardboxes'>low card=<br/>$mincard_display</div></div><br /><br />";		print "<div class='buttons'><input type='submit' name='dowhat' value='BET'>";		print "<input type='submit' name='dowhat' value='PASS'></div>";		}				}else if ($nextaction=="BET")	{		####################		# SCREEN TWO		####################				print "<div class='right_side'><h2>It is $turn team's turn.</h2> <br /></div>";		$wincard=rand(2,14);					$wincard_display=wincardfunc($wincard);				$maxcard_display=maxcard_displayfunc();		$mincard_display=mincard_displayfunc();				$maxvalue=$_SESSION['maxcardsess']; 		$minvalue=$_SESSION['mincardsess'];				print "<div class='cards'><div class='cardboxes'>highcard=<br/>$maxcard_display </div>";		print "<div class='cardboxes'>target=<br/>$wincard_display </div>";		print "<div class='cardboxes'>lowcard=<br/>$mincard_display </div></div>";				if (($wincard<$maxvalue) && ($wincard>$minvalue))		{			print "<div class='buttons'><br /><br/>You win!<br/>";				}else{			print "<div class='buttons'><br /><br/>You lose!<br/>";						}				print "<input type='submit' name='dowhat' value='NEXT DRAW'></div>";		}else{		print "Error 100: nextaction=$nextaction, but I don't know what to do.";	}}?><tt>Website and program by Caitlin Havener. <br/>Card graphics from [url="http://sopapeldeparede.com.br.</tt>"]http://sopapeldeparede.com.br.</tt>[/url]</form></div></div>	</div></div></div></div></div></div></div></div></div></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...