BrettHartel Posted December 6, 2012 Share Posted December 6, 2012 Thank you for taking the time to help me! My "check for cookie" code doesn't work. It doesnt show any errors or do anything. Can someone help me understand what I am doing wrong. I am trying to create the code to check for a cookie. If it doesn't exist I want it to display a <div>information</div>. My code to check for a cookie is called usercheck_cookie.html Here is my code to check for a username: <script> function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } function checkCookie() { var User_ID=getCookie("User_ID"); if (User_ID!=null && User_ID!="") { alert("Welcome again " + username); } else { alert("You are not a user!); echo "<html><div id="Signup" style="position:fixed;width:1000px;height:500px;top:300px;left:50%;background-color:#220916;"> </div></html>"; } } </script> Here is how I set it into my index.shtml: <!DOCTYPE html> <html> <head> <title>Diamond Book Club</title> <!--#include virtual="usercheck_cookie.html" --> </head> <body onload="checkCookie()"> // and the rest of my website is below Sincerely, Brett Hartel Quote Link to comment https://forums.phpfreaks.com/topic/271668-help-with-checking-cookies/ Share on other sites More sharing options...
BrettHartel Posted December 6, 2012 Author Share Posted December 6, 2012 LOL! Sorry everyone. This wasn't php, it was javascript. I changed the cookie check to php and it is working now! Quote Link to comment https://forums.phpfreaks.com/topic/271668-help-with-checking-cookies/#findComment-1397810 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.