0

I have a menu of links that need to have additional parameters added using data from cookies. I need to be able to do this client-side and not server-side.

Basically I have a menu like this:

<ul class="main_menu">
<li><a href="/link/to/page1"> Page 1 </a></li>
<li><a href="/link/to/page2"> Page 2 </a></li>
<li><a href="/link/to/page3"> Page 3 </a></li>
</ul>

And a cookie with a number like this:

users_number = jQuery.cookie("users_number");

I am trying to get the 'users_number' to be included as a POST parameter to all of the links on that menu (ie. /link/to/page1?users_number=thecookievalue) What I don't want is users to be able to see this in their URL bar.

Right now I am using:

jQuery('.main_menu>li>a').attr('href', function() {

users_number = jQuery.cookie("users_number");

return this.href + '?users_number=' + users_number;
});

This functions as I wanted but I am trying to figure out how to do this in a way where the user does not see the ?parameters at the end of their URL. Is there a way to do this same thing but without them being able to see it?

Any help would be hugely appreciated -- thanks!

taylor
  • 509
  • 1
  • 9
  • 22
  • Suggest using session storage on server...then cookies can't be tampered with and no need to display anything to user. Implement a sessions table in db for addiitonal validation, and csrf token system for added secrity – charlietfl Nov 19 '13 at 02:43

1 Answers1

0

One way is by creating a hidden form and then submitting it programmatically.

How can I send POST data and navigate with JQuery?

I don't particularly like this approach though and will try to fetch the cookie from the server side instead. For example in PHP I would use $_COOKIE.

http://php.net/manual/en/reserved.variables.cookies.php http://www.w3schools.com/php/php_cookies.asp

Community
  • 1
  • 1
Maurice Lam
  • 1,577
  • 9
  • 14
  • not goood idea to post links to w3shools around here, far better to point to php manual, or MDN docs...http://www.w3fools.com/ – charlietfl Nov 19 '13 at 02:50
  • I have added the link to PHP manual. Sure w3schools is overused and is not always accurate, but I see no point in not using a link just _because_ it is from w3schools. – Maurice Lam Nov 19 '13 at 03:35