I am building a minor website and for that I am saving a cookie to further continue my code properly but cookie is not getting set then I have copy and paste same cookie setting code on another test page and on that page cookie is getting set properly but same code is not setting cookie here I don't know why please assist me although my code is pretty big so I am uploading below the only cookie setting part: `
<?php
if($val == 1){
if(!isset($_COOKIE['id_cookie'])){
//Fetching id
$sql = "SELECT id from user ORDER BY id DESC LIMIT 1";
$result = mysqli_query($con,$sql);
$id = mysqli_fetch_assoc($result);
$id = implode($id);
//Creating cookie
setcookie('id_cookie', $id, time()+( 365 * 24 * 60 * 60), "/");
if(isset($_COOKIE['id_cookie'])){
echo "Cookie values is set: ".$_COOKIE['id_cookie'];
}else{
echo "Failed!";
}
`
Here each time I am getting failed message of else means cookie is not getting set
Aucun commentaire:
Enregistrer un commentaire