Jump to content

Cookies please?


Beffic

Recommended Posts

Okay so I added a javascript function to make my like easier by opening a new window with the following code.

<Script Language="JavaScript">
function SomeCommand() {
var load = window.open('URL','','scrollbars=yes,menubar=no,height=400,width=300,resizable=yes,toolbar=no,location=no,status=no');
}
</Script>
<a href=javascript:SomeCommand()></a>

Now the java code seems to work and all but when I open the file it doesn't seem to find the cookie in the window mode. But when I open the same file in the browser it finds the cookie and I can proceed. Without the cookie I cannot because it's a login cookie.

 

So is there any idea why it wont read the cookie in window mode but it will in browser?

 

Here is what the cookie is doing. Just in case you are curious. And I know sessions are better but that is not what I am asking for. Thanks.

<?php
if(!isset($_COOKIE['USER_ID']))
  die('Not logged in, please <a href=index.php>go back</a>');
?>

Link to comment
https://forums.phpfreaks.com/topic/133917-cookies-please/
Share on other sites

Well, it seems you're setting the cookie with PHP.  Do you have the cookie set to httponly?  None of that should matter.. it seems like you're reading it with php as well..

 

This example works for me:

test.html

<html>
<head>
</head>
<body>
<script type="text/javascript">
function setCookie(c_name,value,expiredays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

setCookie('USER_ID','1','1');

function SomeCommand() {
  var load = window.open('test.php','','scrollbars=yes,menubar=no,height=400,width=300,resizable=yes,toolbar=no,location=no,status=no');
}
</script>
<a href="javascript:SomeCommand();">a</a>

</div>
</body>
</html>

 

test.php

<?php
print_r($_COOKIE);
?>

 

If you're still having trouble, you need to be more clear about what's wrong..

Link to comment
https://forums.phpfreaks.com/topic/133917-cookies-please/#findComment-697969
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.