0

I'm using JS so set cookies that are named after courses we offer. Since they contain special characters and whitespaces, I encoded them using encodeURIComponent(), like so (see last 2 lines):

$("button[id='ajouter_panier_"+value+"']").click(function(){
        $( "div[id='"+value+"panier']").css( "display", "block" );
        vars++;
        summembre = parseFloat(summembre)+ parseFloat(prixm);
        sumnonmembre = parseFloat(sumnonmembre)+ parseFloat(prixnm);
        $("#nb_"+value+"_cours").text("Qte: "+vars);
        $("#total-commande-nm").text(sumnonmembre.toFixed(2));
        $("#total-commande").text(summembre.toFixed(2));

        titre = encodeURIComponent(titre);              
        setCookie(titre,vars, 1);
    });

It then stores them with this encoding:

Initiation%20au%20cadenassage

Then on the page where I want to get the cookie, I need to do it using PHP.I use rawurlencode() on my title before looking for the cookie in my broswer, like so:

$title = rawurlencode($title);  
$counterMessage = $_COOKIE[$title];

When I echo the value from the new rawurlencoded title, it shows me the same thing that is set in my cookies storage in my Chrome settings:

Initiation%20au%20cadenassage

So, how come I can't get the cookie value when the value I put in $_COOKIE[] is the same I see in my cookies storage?

I know I have the good path and everything since courses titles with no special characters and no spaces are accessed and I can see their value with no problems.

Thank you.

JulesHopes
  • 13
  • 6

1 Answers1

0

Since you are using JQuery already, I suggest you to set and get cookie with the $.cookie, reference here.

You can try to set the encoded string with $.cookie('test', titre), and get it with $.cookie('test')

Community
  • 1
  • 1
Gabriel Cheung
  • 526
  • 3
  • 9