One of the features of PHP that always intrigued me is it’s ability to handle and write cookies.
In a blog that I am coding, I ha e an introduction before the posts start and in the upper right hand corner of the <div> that contains that static intro is an <a> anchor with the text hide.
What I am trying to do is echo a link to stylesheet that hides, by adding display:none;, the intro and the reason I want to use PHP instead of js is that I want to store this action in cookies so that when the user revisits, the intro still hidden.
I have seen something like this is having a theme or stylesheet switched where on click of text a stylesheet is attached and that is stored in cookies so that everytime The page loads the cookies tell it to load that stylesheet they picked before.
I was hoping if someone would be willing to show me how to or give me a sample.of.php that would echo a stylsheet if the hide intro achor, with a class of .hide, was clicked and then store that in cookies so the user does not have to click hide intro everytime.
I would really appreciate any help with this.
Please let me.know if.you have any questions, comments, concerns, or solutions by replying 
Thanks in Advance & Best Regards,
Team 1504.
Something like this should do the trick
if (isset($_GET['toggle_post']) && $_GET['toggle_post'] == true && isset($_GET['post_id'])) {
$post_id = trim(strip_tags($_GET['post_id']));
// Check if a cookie exists already, if one does delete it
// and restore the post
if (isset($_COOKIE['hide_post_' . $post_id])) {
setcookie('hide_post_' . $post_id, false, time()-80000000);
} else {
// Cookie will expire in about 900+ days time
setcookie('hide_post_' . $post_id, true, time()+80000000);
}
}
echo '<div id="post-1"' . (isset($_COOKIE['hide_post_1']) ? ' style="display: none;"' : ) . '>';
echo ' Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
echo '</div>';
echo '<br /><a href="' . $_SERVER['PHP_SELF'] . '/?toggle_post=true&post_id=1">' . (isset($_COOKIE['hide_post_1']) ? 'Show' : 'Hide') . ' Post</a>';
That worked or seemed to work perfectly when I read the code; however, when I ran it on my test server I got this server error
Is there something wrong with the code? Here is the exact document in its entirety.
<!Doctype HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hide post</title>
</head>
<body>
<?php if (isset($_GET['toggle_post']) && $_GET['toggle_post'] == true && isset($_GET['post_id'])) {
$post_id = trim(strip_tags($_GET['post_id']));
// Check if a cookie exists already, if one does delete it
// and restore the post
if (isset($_COOKIE['hide_post_' . $post_id])) {
setcookie('hide_post_' . $post_id, false, time()-80000000);
}
else {
// Cookie will expire in about 900+ days time
setcookie('hide_post_' . $post_id, true, time()+80000000);
}
}
echo '<div id="post-1"' . (isset($_COOKIE['hide_post_1']) ? ' style="display: none;"' : ) . '>';
echo ' Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
echo '</div>';
echo '<br /><a href="' . $_SERVER['PHP_SELF'] . '/?toggle_post=true&post_id=1">' . (isset($_COOKIE['hide_post_1']) ? 'Show' : 'Hide') . ' Post</a>';
?>
</body>
</html>
Do you know what is causing the error and how I can fix it?
Internal server errors are usually due to an incorrectly setup .htaccess file.
On my test Server, I do not have a .htacess file…?
at least not anymore, when I did, all it did was point to want document to redirect the user for 404 and 403 errors.