[pmwiki-users] Cookies and links

DaveG pmwiki at solidgone.com
Fri Feb 19 16:36:34 CST 2010

On 2/17/2010 7:26 PM, pmwiki at 911networks.com wrote:
> On Wed, 17 Feb 2010 17:37:45 -0500
> DaveG<pmwiki at solidgone.com>  wrote:
>>> 1. How can I assign a cookie value when people click on an external
>>> link?
>> You'd need to hook into the javascript click event, and log the
>> cookie from javascript. However, unless you tie the cookie to some
>> form of token/id on the server-side, you should not rely on the
>> presence/value of a cookie for anything which needs to be secure.
> I realize that it's not "secure". I just need people to go through a
> flow. I took a look at: Cookbook/JavaScript-Editable.
Also, consider how you'll want to store the cookies. Do you need a 
cookie per URL that the user clicks, or a single cookie based on the 
fact that they clicked any URL?
> 1. Where do I put the javascript function? In the webpage? in the
> local/config.php?
This is a framework to give you an idea of the approach, written 
quickly, and for ease of implementation, assuming one click for any URL:

<script type="text/javascript" 
<script type="text/javascript">
function ReadCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return "";
	var ind1=theCookie.indexOf(";",ind);
	if (ind1==-1) ind1=theCookie.length;
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
   $(document).ready(function() {
     $(".urllink").click(function(){document.cookie = 
     if (ReadCookie("mycookie"))

You'll need to create a PmWiki markup that provides a marker so the 
javascript knows where you want the replaced image. Above I assume your 
markup creates an image with a class of 'replaceimage'.

If you want to do anything a little more complex with cookies, check out 
the jQuery cookie library: http://plugins.jquery.com/project/cookie

  ~ ~ Dave

More information about the pmwiki-users mailing list