Reputation: 73
I'm planning a registration system. Right now I'm trying to send a randomly generated session string to the mysql db; besides sending it on db I want to create a cookie with the js that contains the session string. I tried with the following code
$sql = "INSERT INTO utenti (utente, email, password, anni, fos, pref, sessione) VALUES(?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param('sssiiss', $ut, $em, $hash, $et, $fos, $gen, $randomString);
$stmt->execute();
?>
<script>
var date = new Date();
date.setTime(date.getTime()+(1202460601000));
document.cookie = "sessione=" + <?php echo $randomString ?> + "; expires=" + date.toGMTString();
</script>
<?php
but I don't know why the cookie is not generated. Would anyone know how to give me a hand?
Upvotes: 2
Views: 45
Reputation: 9301
<?php $randomString = "ffafafasfasfsafaf";
echo $randomString; ?>
<script>
var date = new Date();
var randomString = '<?php echo $randomString ?>';
date.setTime(date.getTime()+(1202460601000));
document.cookie = "sessione=" + randomString + "; expires=" + date.toGMTString();
</script>
I tried this its working for me.
Upvotes: 2