Jump to content

[SOLVED] Update Cookie not working!


wesblake

Recommended Posts

Hello all. I am having an issue with Cookies. I've only used them once before, so I am having a heck of a time tracking down my problem.

Basically, I am creating my own gallery where I want a checkbox for the user to turn on/off exif data under the thumbnails. I will post below the relevant code from my source page, but basically what's happening is the cookie is only set the first time around (when the cookie does not exist) and after that it never updates. I can view it through firefox and verify it is not changing although doing a simple echo "TEST"; in the first if block at the top shows it should indeed be updated. I read some places that if you use the values from the cookie in the same page, you might have to reload first. Even if I reload, the value of the cookie noExif never gets updated! It's driving me nuts. I hope I am clearly explaining this, if not please let me know what clarifications can help. (... is folded/irrelevant code):

 

<?php
if(isset($_REQUEST['noExif'])){
//seconds * minutes * hours * days + current time
$cookie_expire = 60 * 60 * 24 * 365 + time(); 
setcookie('noExif', $_REQUEST['noExif'], $cookie_expire);
       echo "TEST";
}
?>
<html>
<head>
<script language="javascript">
...

function getNoExif(){
if(document.getElementById("noExif").checked)
	return '1';
else
	return '0';
}
</script>
</head>
<body>
<table>
<tr>
	<td nowrap>
	...
	<?php
	...
	//show options
	echo "<p>Options:<br><br>";
	echo "<input type='checkbox' name='noExif' id='noExif' value='1' ";
	if(isset($_COOKIE['noExif']) && $_COOKIE['noExif'] == '1')
		echo "checked";
	echo " onchange='document.location.href=window.location.href+\"&noExif=\"+getNoExif();' /> Thumbnails Only</p>";
	?>
	...
	</td>
	<td>
		<table>
		<?php
		...
					// read EXIF headers
					if(isset($_COOKIE['noExif']) && $_COOKIE['noExif'] == '0'){
						$exif = exif_read_data($subdir."/".$file, 0, true);
						echo "<div align='center' id='exifbox'>";
						// get file name
						echo "File: <b>" . $exif['FILE']['FileName'] . "</b><br/>";
						// get timestamp
						echo "Timestamp: "  . $exif['IFD0']['DateTime'] . "<br/>";
						// get image title
						echo "Title: " . $exif['WINXP']['Title'] . " <br/>";
						// get image subject
						echo "Subject: " . $exif['WINXP']['Subject'] . " <br/>";
						// get image comments
						echo "Comments: " . $exif['WINXP']['Comments'] . " <br/>";
						// get image authors
						echo "Photographer(s): " . str_replace(";",", ",$exif['WINXP']['Author']) . " <br/>";
						// get image dimensions
						echo "Dimensions: " . $exif['COMPUTED']['Width'] . " x " . $exif['COMPUTED']['Height'] . " <br/>";
						// get camera make and model
						echo "Camera: " . $exif['IFD0']['Model'];
						echo "</div>";
					}
		...
		?>
		</table>
	</td>
</tr>
</table>
</body>
</html>

 

EDITED BY WILDTEEN88: When posting code wrap it in code tags (


)

Link to comment
https://forums.phpfreaks.com/topic/113805-solved-update-cookie-not-working/
Share on other sites

Figures. I've spent hours trying to fix this on my own, then as soon as I do a post I figure it out! Sorry. Looks like I have to use $_GET at the top instead of $_REQUEST. Seems odd, but apparently $_REQUEST was not updating with the newly sent value while $_GET was, sounds like a php bug to me.

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.