Jump to content

[SOLVED] moving session cookie data to client cookie


methano

Recommended Posts

I know I'll probably get hammered for not understanding the header problem, but is there a simple way to get data from a MySQL search or from a session variable, into a client cookie?

 

The client cookie already has data in it and I want to change it.  I'd like to put the code on an include page, which is where I seem to get into trouble.  I've tried this with PHP code but would also consider using Javascript to read the session cookie, which also seems to be problematic.

Unfortunately, the data is coming from MySQL via PHP.  I'm trying to embed the javascript instructions to set the client side cookie within PHP and it doesn't seem to work.

 

I use:

 

<?php

$wholerxn = "smith";

echo "<script>function setCookie(\"wholerxn\",".$wholerxn.",5);</script>\n";

?>

 

where the javascript function is

 

function setCookie(c_name,value,expiredays)

{

var exdate=new Date();

exdate.setDate(exdate.getDate()+expiredays);

document.cookie=c_name+ "=" +escape(value)+

((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

}

 

I've probably messes up the syntax.

I finally got the syntax:

 

echo "<script>setCookie('wholerxn','$wholerxn',5);</script>\n";

 

where:

 

function setCookie(c_name,value,expiredays)

{

var exdate=new Date();

exdate.setDate(exdate.getDate()+expiredays);

document.cookie=c_name+ "=" +escape(value)+

((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

}

 

Thought I'd tried that already.

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.