1
I’m starting to mess with cookies, so I don’t know much. I was hoping he’d save a certain <div>
but I don’t know how to do it.
Like I’m doing:
check if that cookie exists:
$nomecoook = $_GET['cont'];
if(isset($_COOKIE[$nomecoook])){
}else{
$sql="SELECT img FROM fotos WHERE tkm='$tkm'";
$exe= mysqli_query($link,$sql);
$numrow=mysqli_num_rows($exe);
setcookie($nomecoook,'1',(time() + (24 * 3600)));
}
the div I want to save:
<div class="carousel-inner">
<?php
$i=0;
while($row=MYSQLI_FETCH_ARRAY($exe)){
$i++;
$img=$row['img'];
if($i==1){
?>
<div class="item active">
<img src="../_img/<?php echo e($img) ?>" alt="First Slide">
</div>
<?php
}else{
?>
<div class="item">
<img src="../_img/<?php echo e($img) ?>" alt="Second Slide">
</div>
<?php
}
}
?>
</div>
I want to save the result of this div so I don’t have to make another query in the database. Can anyone help me?
Or if there’s a way to save the entire page to that cookie.
Usually the browser itself takes care of this, keeping some data cached and updating sometimes, but if you want to save the content in a cookie even, I suggest saving only the essential in json format (with
json_encode
) and, when using, transforms this json into an array or object (json_decode
) to use. If you want to save all the html (not recommend), create a string and add the elements in this string instead of doingecho
– Costamilam
Boy, what a fright! By the title it looks like you want to save the element
div
inside the Cookie!– Wallace Maxters
Oops, but hold on. You’re talking about saving the whole page. Could you explain what you intend to do with it? I’m not talking about what you want to do with the code, but the purpose of this for the end user. It makes no sense to want to put an internal page in a div.
– Wallace Maxters
@Guilhermecostamilam how do I use the cache? , Wallacemaxters n want to save the entire page in a div want the user to enter once that content is saved and next time load faster n knew q had the cache for it
– Cyber Hacker
The browser takes care of the cache, no need to enable it (but it can be disabled in dev tools). If you want to save certain content then I suggest using localStorage for this
– Costamilam
@Guilhermecostamilam I’m new in this area so could you explain to me how you use this
– Cyber Hacker
How to use localStorage
– Costamilam