Set Cookie Wih Js, Read With PHP Problem

Can't read cookie set by javascript in php


<?php
$messsage = $_COOKIE["textout"];
if($message != "") { echo $message; }
else { echo "Fail to read."; }
?>

You're saying $messsage = $_COOKIE["textout"]; , but on your IF your var is $message not $messsage.

Try:

<?php
$message = $_COOKIE["textout"];
if($message != "") { echo $message; }
else { echo "Fail to read."; }
?>

set cookie value in javascript and displaying it with php

i just changed the following

document.cookie='fcookie='+tempo; 

and

if (isset($_COOKIE["fcookie"])) 
echo $_COOKIE["fcookie"];
else
echo "Cookie Not Set";

Get/Read Javascript cookie with PHP

You can use $_COOKIE, the superglobal. Just reference it like you would any array, where $_COOKIE['key_name'] is the cookie you want to access.

See the PHP API documentation.

PHP cannot read javascript cookies


<!DOCTYPE html>
<html>
<head>
<title>example</title>
<script type="text/javascript">
document.cookie = 'name=David' ;
</script>
</head>
<body>
<?php
var_dump($_COOKIE['name']);
?>
</body>
</html>

with this the cookie is set. Did you correct your Typo?
You wrote:

<?php
$encrIv = $_COOKIE['encrIv'];
echo $encriv;
?>

the correct way is to change the echo to

echo $encrIv;

or to change your variable to

$encriv = $_COOKIE['encrIv'];

EDIT:

Maybe your Problem is the not defined Path.
define a cookie like this:

document.cookie = 'sconName='+changedName+'; path=/'


Related Topics



Leave a reply



Submit