Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/271668-help-with-checking-cookies/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.