Does anyone have any idea how to use cookies?

liunx

Guest
I know most people do not like them, but it would make my life a whole lot esier and save space on my server! If anyone knows how to use cookies, any help would be apreciated!<!--content-->i forgot to ask if anyone knoes of a matching field tpe of script to redirect a user to a pecific page after writing some info to a cookie? If anyone does, it would be nice to know.<!--content-->You can redirect to another page using this:<br />
window.location = 'page.html';<br />
<br />
Write a cookie using this:<br />
document.cookie = 'Name=Value';<br />
<br />
And read it using a function like this:GetCookieVariable('Name'); // Returns the value of the cookie called 'Name'.<br />
<br />
// Script by Adam Gundry, <!-- m --><a class="postlink" href="http://www.agbs.co.uk/">http://www.agbs.co.uk/</a><!-- m --><br />
function GetCookieVariable(name){<br />
s = '; ' + document.cookie;<br />
r = new RegExp('; ' + name + '=', 'gi');<br />
p = s.search(r);<br />
if (p != -1){<br />
s = s.substring(p+name.length+3,s.length);<br />
p2 = s.indexOf(';');<br />
if (p2 == -1) p2 = s.length;<br />
m = s.substring(0, p2);<br />
return m;<br />
}<br />
return false;<br />
}<br />
<br />
Hope this helps<br />
<br />
Adam<!--content-->Yes.<!--content-->Try this. i made this a while ago.<br />
<br />
<br />
Javascript: How to use cookies and interact with them.<br />
<br />
Made by myself. Others are allowed to use this freely without my consent.<br />
<br />
<!-- m --><a class="postlink" href="http://www.freewebs.com/sceeuk/index.htm">http://www.freewebs.com/sceeuk/index.htm</a><!-- m --><br />
<br />
<br />
<br />
Hope this helps. <br />
<br />
Does anyone know how to use Cookies? <!-- m --><a class="postlink" href="http://www.freewebs.com/sceeuk/index.htm">http://www.freewebs.com/sceeuk/index.htm</a><!-- m --><!--content-->From my website at freewebs.com: <!-- m --><a class="postlink" href="http://www.freewebs.com/sceeuk/index.htm">http://www.freewebs.com/sceeuk/index.htm</a><!-- m --><br />
<br />
Made by myself. Others are allowed to use this freely without my consent.<!--content-->Cookies can be read and written from Javascript and also most server side languages. There are three types of cookies -<br />
<br />
session cookies are stored in the browser itself and are deleted when the browser is closed<br />
first party cookies are set by the site you are visiting<br />
third party cookies are set by the ads on the site you are visiting (these are the ones you need to turn off)<!--content-->I think it would be better to use a server, here. Not everybody, or every device has javascript enabled. If you have access to php, here's a starting tutorial (<!-- m --><a class="postlink" href="http://www.phpfreaks.com/tutorials/120/0.php">http://www.phpfreaks.com/tutorials/120/0.php</a><!-- m -->).<!--content-->Ironic. This particular post has not been looked at for 3 years, and, long after the problem was solved, someone posts a reply starting the whole thing up again. :p<br />
<br />
Not to be rude, thanks for the help -- I'll certainly know where to send anyone else who asks me :cool: <br />
<br />
This just reminds me of a joke i heard a while ago about how to ask for something on a lightbulb. You get like 1,000 people responding, then the post dies. Then someone replies and starts the whole process again.<br />
<br />
Cheers!<!--content-->
 
Back
Top