mardi 29 août 2017

Cookie not found when opened with a link

so somehow I ran into an issue no one else has.

I have two PHP documents, one that sets a cookie when a link is clicked and one that is opened by the link and is supposed to display the cookie.

The odd problem is that the page opened by the link will display this error about the cookie - "Notice: Undefined index: imgPath in /home/sitespage.php on line 19"

(imgPath is the cookie name) However, there is no issue when the page is opened from the browser and not through the link and the cookie is displayed normaly and I have no clue why this is happening.

Here is the code for the page hosting the link -

<a href="http://link.php" target="_blank" onclick="document.write('<?php setcookie("imgPath","56",time() + 60 * 60 * 24); ob_end_flush(); ?>');">
    <?php
      echo $post1;
    ?>
</a>

($post1 is an image)

and this is the code for the link page

echo $_COOKIE["imgPath"];

thank you for any and all help




Aucun commentaire:

Enregistrer un commentaire