php - Checking if there is a cookie set, if not output script -
i try use php check if cookie set. if not want script output. if set don't want anything.
i not programmer , have no clue start this. have done lots of searches on google no avail.
cookie name = subscribed
the javascript source required output mysite.com/js/subscribe.js
thanks
if(isset($_cookie['subscribed'])) { // if cookie there $subscribe = false; } else { // if cookie not there $subscribe = true; }
you use basic isset check first, somewhere in top of file before output. in head, in html this:
<head> <!-- standard head meta here --> <?php if($subscribe): ?> <script src="http://mysite.com/js/subscribe.js"></script> <?php endif; ?> </head>
you run inline, or use javascript check cookies. 1 example , handled in case else needed processed, unset, or else make sense of having cookies checked before output sent.
shorter version use in place of longer conditional above:
$subscribe = isset($_cookie['subscribe']) ? false : true;
Comments
Post a Comment