Read a Javascript cookie with PHP -


I have some JavaScript code that sets cookies and when I try to read that cookie with PHP It says that it is undefined.

  notice: undefined index: score: c: \ xampp \ htdocs \ Contest \ score.php on line 44   

I use xamp to run Doing and testing PHP on my computer, can it be the reason why he is not reading the cookie?

This is my code

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; PHP written test & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body style = "background-color: # ADD8E6; margin-left: 25%;" & Gt; & Lt ;? Php included 'variables.php' ;? & Gt; & Lt ;? Php included 'functions.php';; & Gt; & Lt ;? Php session_start (); $ X = 1; $ Y = 0; $ Score = 0; While ($ x & lt; = 20) {$ a = $ _POST ["question" $ X]; $ B = $ _SESSION ['true'] [$ y]; $ C = $ _SESSION ['question'] [$ y]; If (trim ($ a) == trim ($ b) {$ score ++; } And {echo "$ c 
was your answer: $ a
The correct answer is: $ b


"; } $ X ++; $ Y ++; } "$ Score / 20" echo; Echoes $ _COOKIE ["Scorecount"]; ? & Gt; & Lt; / Body & gt; & Lt; / Html & gt;

I will post a picture to prove that the cookie is set correctly but I do not have enough representative. When I look at all the cookies in my web browser, the cookie is "scorecount" and it is set correctly, if someone tells me what I am doing, thank you very much!

sets my JS cookie

  function getCookie (c_name) {Warning ("Im in GateQooqi"); Var i, x, y, ARRcookies = document.cookie.split (";"); (I = 0; i & lt; ARRcookies.length; i ++) {x = ARRcookies [i] .substr (0, ARrakis [i] .indexOf ("=")); y = ARRcookies [i] .substr (ARRcookies [i] .indexOf ("=") + 1); X = x.replace (/ ^ \ S + | \ + + / g, ""); If (x == c_name) {back to UNESCO (Y); }}} Function set cookie (c_name, value, exdays) {warning (im in "set cookie"); Var exdate = new date (); Exdate.setDate (exdate.getDate (+) Exdays); Var c_value = escape (value) + ((exdays == null)? "": "Expires =" + exdate.toUTCString ()); Document.cookie = c_name + "=" + c_value; Warning ("cookie set"); } Function check cookie (end) {warning ("im check check"); Document.getElementById ('FULL'). Ondragstart = function noDrag () {return false; }; Var score = getCookie ("Scorecount"); If (score! = Null and end score! = "") {If (end == 'yes') {score = score - 1; Return score; Warning ("Your Score" + Score); } And {score = 1; If (score! = Null and score! = "") {Set cookie ("scorecount", score); // Alert ("Your Score" + Score); }}} Function right (pgnmbr) {var val; val = getcookie ('scorecount'); Val = parseInt (val) + 1; setcookie ('scorecount', val); location.href = loc (); Warning (val); } Function right 2 (pgnmbr) {var val; val = getcookie ('scorecount'); Val = parseInt (val) + 1; setcookie ('scorecount', val); location.href = loc2 (); } Var click = 0; Function incorrect (pgnmbr) {click ++; If (click & lt; 3) {warnings ("wrong try again"); } And {warnings ("You have exceeded your trys"); Location.href = loc (); }} Document.getElementsByClassName ( 'box1') [0] .addEventListener (click ', true, false); Document.getElementsByClassName ('bg') [0] .addEventListener ('click', wrong, incorrect); Okay, I have solved my problem, apparently you can only read a cookie that was set on it. The same domain ... thanks to # Duh #Noobie suggestions though guys !!   

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -