Cookies.get(name);

I am trying to verify cookie exists to block pop-up from showing. I have tried 10 different pieces of code and all fail. I think the problem resides in waht I am using for c_name. Latest attempt below. I have tried the cookie name and the domain name. Neither work.

<script>	
function checkForJALACookie(c_name){
	var cookieFound = Cookies.get(c_name);
//    alert("cookiefound = " + cookieFound);  <-undefined
    if (cookieFound) {
	  alert("Cookie Found");
       } 
    else {
        alert("Cookie Not Found");
      }	
 }    
</script>	

The storage inspector shows cookie name CGISESSID. I set the cookie in my code

What am I missing here?

Thanks for any insight.

…so… what are you using for cname?

c_name = ‘CGISESSID’

Only debugger message

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://1.2.3.4/cserver/clientresptime?cid=CID5181430.AID1533095012.TID10763&url=http%3A%2F%2Fjala-mi.org%2F&resptime=26773&starttime=1533386317466. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

CORS Enabled makes no difference

Cookie

Have screen shot of cookie data but don’t see where to attach

Thanks

copy/paste or drag drop into the post box and it’ll handle the posting of the screenshot.

Where are you invoking this function? What are you passing as c_name?

This is a testing block

<script type="text/javascript">

$(document).ready(function(){	
     var name = "CGISESSID";
     alert("calling check cookie then resize from ready");
     CheckForCookieEnabledBrowser();
//	 var c = $.cookie('CGISESSID');
//	 alert(" C = " + c);
     checkForJALACookie(name);


//     if (!checkCookie()){
//       	 resizeEvent();
// 	 }
 });

</script>


<script>	
function checkForJALACookie(c_name){
	var cookieFound = Cookies.get(c_name);
   alert("cookiefound = " + cookieFound);
    if (cookieFound) {
	  alert("Cookie Found");
      console.log("Cookie found. No action necessary");
     } 
    else {
      alert("Cookie Not Found");
      console.log("No cookie found.");
      }	
 }    
</script>

My reply did not post the code???

cookie

Hi thanks for heads up.
I am more familiar with the Monks method

<code>

code here

</code>

1 Like

The domain on that cookie looks… wrong. It’s got a leading . Are you sure it’s being SENT?

console.log(document.cookie)

If that site is live I think you should remove the alerts and use only console.log.

For a non-techy visitor a bunch of alerts would likely put them off. And a non-techy visitor is not likely to look at their dev tools and see the log messages.

The alerts are just there to test live.

Interesting:} If I go to jala-mi.org it gets nothing for value.

If If I go to www.jala-mi.org I get a return value

alert

So your problem is the cookie domain setting.

You mean the .www as opposed to www?

I have no control over that: perl

my $domain = $ENV{'HTTP_HOST'};


sub SetUserSessionCookie
{   
    my $printresult = "";
    my ($sname,$sid) = @_;
    my $sessioncookie = new CGI::Cookie(-name=>$sname,-value=>$sid,-  expires=>$session_cookie_timeout,-path=>'/',-domain=>$domain,-secure=>0);
    $printresult = print header(-Cookie=>[$sessioncookie],-type=>"text/html");
    warn("printresult: '$printresult'");
   
}```

Working now test here

http://www.jala-mi.org/index_test_cookie.html

Well not quite. If I am logged in and put just jala-mi.org in the address bar, it does not see the cookie!!

Interesting: Storage inspector show cookie for www.jala-mi.org and cookie for jala-mi,org.

www.jala-cookie has data the jala- cookie has no data.

??? Lost

Took out c_name in get and works on all now, Good grief.

T*hanks all for support and steering in correct direction.

Robert

Got up this am and fail. Put c_name back in and prepend www to url if not included using .htaccess.

Seems to work. Holding breath

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.