Jump to content


Photo

Session problems or something else


  • Please log in to reply
2 replies to this topic

#1 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 09 August 2006 - 03:14 PM

I have a users page that has this in it:

function GetRandomChar() {
	mt_srand((double)microtime()*1000000);
	$IMGVER_RandVal = mt_rand(1,3);
	
	switch ($IMGVER_RandVal) {
	case 1:
		$IMGVER_RandVal = mt_rand(97, 122); 
		break;
	case 2:
		$IMGVER_RandVal = mt_rand(48, 57);
		break;
	case 3:
		$IMGVER_RandVal = mt_rand(65, 90);
		break;
	}
	return chr($IMGVER_RandVal);
}
function register_form(){
         global $db, $prefix, $name, $email, $username, $password, $user_taken_err, $email_taken_err, $name_taken_err, $type;
if($type == "f"){
	$nameout = "Your";
}elseif($type == "b"){
	$nameout = "Band";
}else{
	$nameout = "Your";
	$type = "f";
}

	session_start();

	$IMGVER_TempString="";
	
	for ($i = 1; $i <= 6; $i++) {
	   $IMGVER_TempString .= GetRandomChar();
	}
	
	$HTTP_SESSION_VARS["IMGVER_RndText"] = $IMGVER_TempString;
	$IMGVER_RandomText = $HTTP_SESSION_VARS["IMGVER_RndText"];

echo "<div style=\"text-align:center;\"><span class=\"title\">Registration form</span><br />";
echo "Fields marked with a * are required.
      <form id=\"RegisterForm\" method=\"post\" action=\"users.php\">
      <table style=\"margin:0 auto;width:400px;\" border=\"0\" id=\"table1\" cellpadding=\"2\">
		<tr>
			<td style=\"text-align:right;width:50%;\">$nameout Name:</td>
			<td style=\"text-align:left;width:50%;\"><input type=\"text\" name=\"name\" size=\"20\" value=\"$name\" /> * $name_taken_err</td>
		</tr>
		<tr>
		  <td style=\"text-align:right;\">E-Mail:</td>
		  <td style=\"text-align:left;\"><input type=\"text\" name=\"email\" size=\"20\" value=\"$email\" /> * $email_taken_err</td>
	    </tr>
		<tr>
		  <td style=\"text-align:right;\">&nbsp;</td>
		  <td>&nbsp;</td>
	    </tr>
		<tr>
			<td style=\"text-align:right;\">Username:</td>
			<td style=\"text-align:left;\"><input type=\"text\" name=\"username\" size=\"18\" value=\"$username\" /> * $user_taken_err</td>
		</tr>
		<tr>
			<td style=\"text-align:right;\">Password:</td>
			<td style=\"text-align:left;\"><input type=\"password\" name=\"password\" size=\"18\" value=\"$password\" /> *</td>
		</tr>
		<tr>
		  <td align=\"right\">Verify Image:</td>
		  <td align=\"left\"><img src=\"doimg.php?"; echo SID."\" /><br /><input name=\"verify\" type=\"text\" id=\"verify\"></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td><input type=\"submit\" value=\"Register\" /> 
			<input type=\"hidden\" name=\"cmg\" value=\"do_Register\" />
			<input type=\"hidden\" name=\"type\" value=\"$type\" /></td>
		</tr>
	</table></form>[ <a href=\"users.php\" title=\"Back\">Back</a> ]</div>";
}


here is doimg.php

<?php
$IMGVER_IMAGE = imagecreate(150,40);

$IMGVER_COLOR_BLACK = imagecolorallocate ($IMGVER_IMAGE, 0, 0, 0);
$IMGVER_COLOR_WHITE = imagecolorallocate ($IMGVER_IMAGE, 255, 255, 255);

imagefill($IMGVER_IMAGE, 0, 0, $IMGVER_COLOR_BLACK);

session_start();
$IMGVER_RandomText = $HTTP_SESSION_VARS["IMGVER_RndText"];

imagechar($IMGVER_IMAGE, 4, 20, 13, $IMGVER_RandomText[0] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 5, 40, 13, $IMGVER_RandomText[1] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 3, 60, 13, $IMGVER_RandomText[2] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 4, 80, 13, $IMGVER_RandomText[3] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 5, 100, 13, $IMGVER_RandomText[4] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 3, 120, 13, $IMGVER_RandomText[5] ,$IMGVER_COLOR_WHITE);

header("Content-type: image/jpeg");
imagejpeg($IMGVER_IMAGE);
?>

I have used this same thing on a contact page and it works fine. When I go to register now there is just a blank black box. When I go to the contact page, that image loads fine, when I go back to register the same code appears as the contact page I was just on.

Am I missing something? Do you need any other code to look at?

Thanks,
-Chris

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 09 August 2006 - 05:42 PM

the image is being cached

Common problem, simply stop that image, or the whole page from being cached
Tell me the problem, I will try tell you the solution

#3 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 09 August 2006 - 05:45 PM

Right, but the initial problem is that when you first go to the registration page, there is nothing in the image. There wouldn't be any caching problems if it was actually generating something...which it's not.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users