Jump to content

cookie


djp1988

Recommended Posts

Do a Google search for Javascript cookies, but you can't access a cookie with PHP on the same page when it's set, you can only access it once it gets sent to the server (it doesn't get sent to the server on the same page that it's set).

Link to comment
Share on other sites

A cookie that's already been set (on a previous page load) is available as soon as your page is called. It gets sent along with all the other headers and junk that are usually invisible. The $_COOKIE variable works just like the $_POST variable. Whatever key you stored your cookie value under will be the key to access it in $_COOKIE. It's almost too easy to mess up. http://www.php.net/manual/en/reserved.variables.cookies.phpIt looks like you're setting preferences, like font size or whatever. So at some point, your user clicks a button. You set your cookie. NEXT TIME your user accesses your page, your PHP gets the font size from the cookie. In your CSS section, you nest a php tag that puts the cookie value where the font size goes. Boom. You're done.

Link to comment
Share on other sites

I want to do the following:

window.onload = init;function init(){	document.clicker.onsubmit = function(){saveCookieinfo(this);}}function saveCookieinfo(){	var now = new Date();	now.setTime(now.getTime() + 1000 * 60 * 60 * 2);	document.cookie = "topvote=1; expires="+now;	document.getElementById("Layer1").style.display = "none";}

withe the following php:

<?php if($_COOKIE['topvote'] != 1){echo '<a target="_blank" href="..."  title="..."> <img border="0" src="..." width="90" height="50"></a><br /><form id="voteForm" name="clicker" action="..." target="_blank" method="POST"><input type="hidden" name="s" value="..."><input type="hidden" name="id" value="..."><input type="submit" value="Voter pour ce site"></form><p class>';}?>

So people can vote but onle once every 2 hours, so when the form is submitted, i want to make the cookie, and hide the layer it's in, and then when people carry on browsing, if the cookie is still there, so it's been less then 2 hours, the php doesn't render the form and rest... but, because I have not got return false in the js, because I want to post data to another window (_blank), the code doesn't work, the layer doesn't disapear...How can I get my js code on the onsubmit to execute whilst i allow the form to submit as default to a new window?

Link to comment
Share on other sites

please don't pay attention to this post now, my fault, i was submitting this form on a page that had not loaded completly because it was very long page, that is why the effect wasn't working, and against my loyal anti-inline javascript i have added an onsubmit="" in the <form> tag :)i guess the main thing is that it works

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...