Jump to content

Recommended Posts

You don't put it into a stupid format to begin with? Although, that "should" work, but there can be multiple problems. A: Cookies do not show up till a page reload (if I remember correctly). B: You should set an expire time and path.

 

setcookie("myCloud[loginID]", $value, time()+3600*4, "/");

 

Shoudl set it to expire in 4 hours valid on the root of the webroot. See if that does you any better.

Link to comment
https://forums.phpfreaks.com/topic/242558-cookie-help/#findComment-1245717
Share on other sites

why do they need a path?

 

They do not always need it, but since you are having troubles you need to think outside of the box and try some of the other items that setcookie has to offer. And of course the isset check did not work, your cookie is not being set to begin with. So take a look at the setcookie man page and try some of the optional options for it, go one by one or try all of them at once and see if it kicks in. If that still does not work, change the cookie name to not have the braces ( [] ) and see if it works then.

Link to comment
https://forums.phpfreaks.com/topic/242558-cookie-help/#findComment-1245723
Share on other sites

do you usually set the httponly to 1, or 0?

 

they have an example using ['s:

 

<?php

// set the cookies

setcookie("cookie[three]", "cookiethree");

setcookie("cookie[two]", "cookietwo");

setcookie("cookie[one]", "cookieone");

 

// after the page reloads, print them out

if (isset($_COOKIE['cookie'])) {

    foreach ($_COOKIE['cookie'] as $name => $value) {

        $name = htmlspecialchars($name);

        $value = htmlspecialchars($value);

        echo "$name : $value <br />\n";

    }

}

?>

 

 

http://php.net/manual/en/function.setcookie.php

Link to comment
https://forums.phpfreaks.com/topic/242558-cookie-help/#findComment-1245728
Share on other sites

A: Cookies do not show up till a page reload (if I remember correctly).

 

should i be using a session instead? that's what i was using before, but i wanted to use cookies for the "remember me" feature. (or couldn't i even use sessions to also create a remember me?  i think that it is usually cookies that they choose to use though...)

Link to comment
https://forums.phpfreaks.com/topic/242558-cookie-help/#findComment-1245730
Share on other sites

droidus, session would work a bit better in your case. If you want the "remember" me type functionality, you can just set the session to use cookies and you can set their timeout as well. You should be able to do this by editing the php.ini see session for more information.

Link to comment
https://forums.phpfreaks.com/topic/242558-cookie-help/#findComment-1245901
Share on other sites

The session requires the use of a cookie. Why people use cookies over sessions? Well leaving the same session hash for a user over time dilutes it, meaning a greater chance for someone to hi-jack their session. You still have to store something in the database to authenticate the user from, so most people opt to store a userid and a hash (a random hash stored in a database) to authenticate people from and they often re-generate this hash each time a user logs in. This way their hash is not diluted, they can be re-authenticated easily and is a bit more secure then leaving the same hash on their system for days on end. That and it is a bit easier to control an actual cookie over control a session cookie, as the session cookie requires editing the php.ini or using ini_set methods to modify and is generally done globally. Where as with cookies you can easily tailor it to user input with a simple change in the expires time.

 

So yea. It all depends on the need. 

Link to comment
https://forums.phpfreaks.com/topic/242558-cookie-help/#findComment-1246162
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.