Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Cookie


my plan is to create a usersystem where whenever they sign up the script sets a cookie for the username & password, and then throughout the site it will use these cookies
my questions...

1) how do i set the 2 cookies to never expire (if its possible)
2) how do i recall the stored username/password cookies properly.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Cookie
How do you set a cookie for a login page to get the browser to remember the login info.

Also, I read that :

header("cache-control: private") or something close causes IE to maintain form post data in case an input error is made and the user needs to go back to the form. Is this accurate?

Can Someone Please Help On Cookie
I am trying to set an email address as a cookie using setcookie() function. The problem I see is that the character, '@' becomes '%40'.

I want to see the original @, is this possible in PHP? Using a perl cgi works fine.

Also, can cookies be set without using setcookie()? I tried to use print "Set-Cookie: email=xxx@yyy.zzzz;..."; etc, before any header or output but things are printed on the browser.

PHP Ate My Cookie
I am trying to use a set a cookie whenever someone fills out a registration form on my site. Code:

Cookie
I got a simple page index-tmp who include a code snippet who test if a cookie
exist and if yes redirect to the user account page but the trouble
is when I didn't 've a cookie the page still redirect to the user account page.

here is the following code :

<?
$cookie = $_COOKIE["free-nickname"];
if (!cookie == null) {
echo '<script langage = "javascript">'
echo " document.location.href = 'index_utilisateur.php'";
echo '</script>;'
}
else {
echo '<script langage = "javascript">'
echo " document.location.href = 'index.php'";
echo '</script>;'
}
?>

Php Cookie
I am wanting to set a redirect in the surfers browser that will redirect the surfer
to a different page the next time the surfer returns.

For example, if the visitor visits home.php a cookie will be set and so the next time the visitor returns to this page, the cookie will be detected and the surfer will be redirected to newpage.php.

Cookie Set In A Different Dir
I'm basically trying to read and use the cookie set by the YaBB forum on my site on the index page, as a kind of 'welcome' to users who have accounts in the forum. I thought this would work;

<?php
if($HTTP_COOKIE_VARS['YaBBusername']) echo ("Welcome back, " . $YaBBusername . "!");
?>

in it's simplest form. Now, I know that YaBBusername is the name of the cookie, as I have found it on my HD and read it. I've also gone through the forum code and checked it does set the cookie with the path=/ so it should be able to be read on all directories, shouldn't it?

I might also point out the forum is in my cgi-bin, whereas the index page is obviously located in the root folder. I'm really stuck on something I thought would be quite easy.

Set A Cookie
What I'm trying to do here is check if the value of the cookie is equal to what it was set to. If not, set the cookie and reload the page. The problem is that the webpage keeps on reloading, probably because the cookie wasn't set, or there's an error in my code. I've tested other code with cookies and it's worked.

A couple questions... What's wrong with the code? And do I need to reload the page to read the cookie after it just got set? Code:

Cookie
I am executing a cgi-script using a username and password sent via hidden fields from another location. This cgi-script simply creates database records (if the first time this user has visited), then needs to pass control to a static html page. By the time I get to the html page, I need to have a cookie set, but we don't want any screens to show up in between - basically the whole cgi-script processing is invisible. Once finished with
the update, I send the username via a hidden field in an autosubmitted form
to a php script in order to get the cookie set.

Now, in order to get the cookie set, I execute a 'self-check' routine in php
(this routine is right out of the Professional PHP Programming Book, by Wrox
Press). This scripts sets the cookie then redirects to itself. The second
time through this script, it checks to see if the cookie exists - if it
doesn't, it gives a message "...Please enable cookies". If it does - it
redirects to the static html page. The code is below.

My problem is that the first time through this whole process (cgi-script to
php script - in a new browser session), I get the error "...Please enable
cookies" (which I DO have enabled). If I then send through a second username
and password and go through the whole process (same browser session) - this
time it works, and sets the cookie with the second username. Code:

Php Cookie
I have the following code to set cookies but AOL users seem to have a hell of a problem with it. Is this bad php coding? Should I use an alternative method? Code:

setcookie($cookiename . '_data', serialize($sessiondata), $current_time + 31536000, $cookiepath, $cookiedomain, $cookiesecure);

setcookie($cookiename . '_sid', $session_id, 0, $cookiepath, $cookiedomain, $cookiesecure);

Cookie
i'm experiencing one problem regarding setting the cookie. may i know why the cookie that i set in IE can't appear in Netscape? what i mean the page that i view using netscape are without cookie while in IE display the cookie page?

Cookie
I have a website that is accessible (at least from our local campus
network) by four different ways:

1) the full url: http://campuslaan37.student.utwente.nl/
2) the short url: http://campuslaan37/
3) an alias: http://cam37.student.utwente.nl/
4) the short alias: http://cam37/

I use cookies to save and set some preferences etc. However, if you
surf from e.g. (1) to (3), it is treated as an entirely different
site, and nothing that was stored in the cookie applies anymore.

Is there a way to set the cookie, such that it immediately applies
to all the possible URLs to access the site?

Cookie Won't Set
This was working up until a short while ago, and now the cookie won't set. Is something wrong all of a sudden?

$id=$_GET['id'];    //$id is a number passed through the url

setcookie ("ringi", "ringi/approval.php?id=$id", 0, "/");

PHP Cookie
with my website sometimes users login in and yet when they try to enter it takes them back to the login page telling them there not logged in, now im assuming this has something to do with the cookie keeping, but then again im still a newy and still learning it all, but i will paste my cookie code to see if it may hold the key to my problem as not all users get this issue. Code:

Cookie Won't Set.
I just made a login script and I made it so the user could check if they want to stay logged in forever. But when they check the box the cookie won't initiate. If they don't check the box, the session registers just fine.

<?php

if (isset($_POST['stay_logged'])){ 
      setcookie("sid", $row['userID'], time()+360000); 
} else { 
      $_SESSION['sid'] = $row['userID']; 
}?>

I made sure that $_POST['stay_logged'] was set, so thats not the problem.

Cant Set Cookie
i am just making a very basic shopping cart/basket on my site and im tracking which user in the DB by putting in their session id as the unique CartID for each user.

i have this located in an include file with my database information, and the cookie is not being set, i cannot view it through echo and checking it in IE's temp files and Mozilla's cookie viewer shows it is not being set. i dont understand what i am doing wrong any help will be great, this is my include. Code:

Cookie
I made a site using CMS Dragonfly 9.1.1 and I'm having the same problem and I was having a long time ago but the site that was helping me had a problem with some array thingy, anyway.

It's a problem with the cookies, it stops you from loging out, or causes the site to give you a 404 error sometimes, and it causes all kinds of problems, and I was wondering if you guys have heard of the cookie mod or not? That fixed my first site so I was wondering if it would fix this too.

Cookie / GET
I've been trying for a number of days to get a delete function working. The problem is, I can't get the delete.php page to actually do anything. So, I changed my method of deleting from a link next to each picture to a checkbox system. Here's the code that shows all the directory's files with the checkboxes next to them: Code:

Cookie
Im setting a cookie like this:

setcookie("imagestatus", "1", time()+ (86400 * 30));//30 days

But my if statement is not evaluating as true

if ($_Cookie['imagestatus']=="1")

any suggestions ?

Session Or Cookie
I have a simple question what should i use on a e-comerce site
session or cookies ??nor can i use both systems ?

Cookie Problem
How come this wont set??

$cookie_info="Yes";

$cookie_sql = "select * from $users where
username='$user'and set_cookie='$cookie_info'";

$cookie_sql_result = mysql_query($cookie_sql,$connection) or die
("Could not execute cookie_result");

while ($cookie_row = mysql_fetch_array($cookie_sql_result)) {

if ($cookie_info["set_cookie"] == "Yes")

{
setcookie($user, $pass, time() + 2,592,0000); //sets cookie for 1 month.
echo "cookie has been set!";
}

Can't Delete Cookie
Right I am quite new to php but have managed to create a simple log in/log out thing with cookies. All was working fine and as expected until I added a new section of the site. The new section stores another cookie (latest message user has read) so that next time they visit the site it will highlight the 'new' messages.
However since adding this I can no longer log out.

Cookie Problem
i always facing a problem in setting the cookie. the cookie that i set always return a empty value.

my code is as follw:
setcookie("weather", $location, time()+14400);

where the value of location is the value from selection list.
can somebody help me to solve this problem?

Cookie Crumbling
I've never used cookies before, and I've read many many tutorials and all of the php.net documentation, but I can't seem to figure out how to do this.

I have a poetry site that uses a voting script to register votes in a mySQL database. I create a cookie using the unique ID of the poem that the user has voted on.

My problem is that I need to store this unique ID in a cookie for each poem they voted on. As it stands now, the cookie is updated each time the person votes, but only prevents them from voting on the same poem more than 1 time in a *row*. If they vote on 1, then vote on another, then vote on the first one again, the cookie lets them vote.

How could I store these ID values in a cookie in such a way that I could check to see if *any* of the values for the id field are present in the cookie variable, not just the one value?

BTW, I've already been through the procedure for storing multiple cookies, but I'd rather not store many dozens of cookies on anyone's machine if they vote a lot.

Is There A Cookie Buffer?
Is there a maximum number of cookies allowed from one web site? I have a voting system that saves a cookie for every vote so that the user won't re-vote for the same item. (they are set to last one year). It appears that only so many cookies are allowed because they are expiring as I make new votes...?

Can't Delete Cookie, Help Please~
Page1: <? setcookie("book_id", $book_id ); ?>

Page2: <? setcookie ("book_id", $book_id, time() - 3600); ?>

Can't delete cookie at once but reload page 2 two times
how to delete $book_id cookie without reload?

Remove A Cookie?
In my site i have a login button that if pressed it goes to a login page. After inserted the username and pass he creates a cookie called user. I also have a logout button that remove the cookie.

the question is how can remove a cookie called user?

Broken Cookie
I have a little poll on my website that until recently worked perfectly. People vote, then the results are shown, and when they come to the site again, the results are shown with a little message saying that you can't vote twice.
However, with IE6, people can vote as many times as they want by simply closing and re-opening their browser, i.e. the cookie that says they have voted is being ignored or deleted.

The code I am using is:

Cookie Won't Delete
I'm trying to setup a simple user authenication for my site. I'm using cookies to pass the credentials between pages. But the function header() is giving me problems logging in and logging out. As you can see in the code below, I try to redirect the user to a page after setting or deleting the cookies. The scripts redirect okay, but the user never logs in and never logs out correctly. The scripts works correctly (logging in & logging out) only if I comment out the header() function.

Here's my code for setting the cookie (login.php):

Cookie Problem
My site uses cookies to remember who referrered them to the site.
The cookie looks like this PHP Code:

Cookie Problem
Ok i now when you make a setcookie(); that var will be global. i only have 1 problem why wont this simple script just wont make a cookie on my pc and other pc's. i have been trying to make this work for 2 days now and it just doesend work HELP!!!

Code:
<?
if ((!isset($VarSource)) || ($VarSource != "a Cookie"))
setcookie ("VarSource",$VarSource);
else
setcookie("VarSource");
?>
<html>
<head>
<title>Een ogenblik geduld graag</title>
</head>
<body background="../../images/bckgr_img.jpg" bgproperties="fixed" scroll="no">
<?
if (isset($VarSource))
print("VarSource : $VarSource<br>");
else
print("VarSource niet verzonden");
?>
<p>This is a self posting form
<form method="post" action="<? echo $PHP_SELF?>?VarSource=Get">
<input type="submit" value="submit">
<input type="hidden" name="VarSource" value="Post">
</form>

Cookie Restriction
I've read that php can only handle 20 cookies /server. Is this true?

We want to have many people logged in at the same time and every page checks in the cookie if the user is logged in. And we do want to have "way" more than 20 users logged in at the same time.

Cookie Not Working
I have a script which handles info coming from a html form. I wish to stop multiple submissions by making the user wait 60 seconds before its possible to re-submit.

I have this working correctly in one script but the identical code pasted into another script no longer works. PHP Code:

Cookie Difference IE/FF
Hello all,
I'm trying to do something very simple: delete (or empty) a cookie.
The following code (which I found in the PHP doc) works fine in IE6 but not
in Firefox:
setcookie ("Cart";, "", time() - 3600);
Any hint on what's wrong ? Yes, I issue this command before sending in any
HTML.

I Need Help With Cookie Detection!
Ok I can't seem to get this script to work. All it doe's is verify a cookie and query the database for the value of the cookie. If the cookie's not set it sets the cookie. heres the code....

98% Done With Cookie Script - Need Help
I've been working on this for a while, and I really am hating cookies. After figuring out that my book has errors, I'm really stumped.

This script should:
1. Look for a particular cookie value
2. If that cookie is not there, place one.
3. Based upon a cookie value and user entered form value, display variying content


Simple, huh? Hell no.

The following script has 2 parts. An index.php page and a validate.php page.

Index.php has the cookie value validator and user form. Validate.php has the cookie placer.

This is the index.php file

<?
$content = "";

IF(!$HTTP_COOKIE_VARS["variable"]) {
setcookie("validate","blank",time()+31101000,"/","opus.solarcom.net",0);
}

IF($HTTP_COOKIE_VARS["variable"] == "solarcom"){
$content="solarcom";
}
else if ($HTTP_COOKIE_VARS["variable"] == "atlantix"){
$content="atlantix";
}
else if ($HTTP_COOKIE_VARS["variable"] == "comlanta"){
$content="comlanta";
}
else {
$content="question";
}


echo "<HTML>
<HEAD>
<TITLE>Set the test cookie</TITLE>
</HEAD>
<BODY>
I love cookies <BR> and <BR>";

$form = "<FORM METHOD="post" ACTION="validate.php">
<p>I work for:<br>
<input type="radio" name="company" value="solarcom">Solarcom<br>
<input type="radio" name="company" value="atlantix">Atlantix<br>
<input type="radio" name="company" value="comlanta">Comlanta<BR>
<INPUT TYPE="submit" NAME="submit" VALUE="submit">
<BR>
</p>
</FORM>";

if ($content == "solarcom"){
echo "solarcom";
}
else if ($content == "atlantix"){
echo "atlantix";
}
else if ($content == "comlanta"){
echo "comlanta";
}
else if ($content == "question"){
echo "$form";
}

echo $content;

echo "</BODY></HTML>";

?>
This is the validate.php file. As far as I can tell, this one is working fine.
<?
if ($company == "solarcom"){
setcookie("validate","solarcom",time()+31101000,"/","opus.solarcom.net",0);
}
else if ($company == "atlantix"){
setcookie("validate","atlantix",time()+31101000,"/","opus.solarcom.net",0);
}
else if ($company == "comlanta"){
setcookie("validate","comlanta",time()+31101000,"/","opus.solarcom.net",0);
}
?>
<HTML>
<HEAD>
</HEAD>
<BODY>
<A HREF="index.php">Go Back</A>
</BODY>
</HTML>


Ok, I'm getting the following errors in index.php

"Warning: Undefined index: variable in D:InetPubwwwrootindex.php on line 11"

Location Of Cookie
I am using the cookie and session to protect the web site. I am having problem with netscape in windows 2000. I want to know which location does netscape saves the cookie or how does the setcookie command differs in their working in win98 and win2000. I tried to destroy the cookie in win2000 but I could not find the location of cookies directory in win2000 but the program works ok with win98- all browser and windows 2000 all browser except netscape. As a first measure to detect whether it is the problem of cookies or not, I want to destroy the cookies in Netscape and check.

If I Set Cookie Using CGI, Can I Read It Using Php ?
if i set cookie using CGI, can i read it using php ? i have a cgi file that sets this cookie.

#!/usr/bin/perl -w

use CGI;

my $query = new CGI;
my $value = "testcookie";

my $cookie_out = $query->cookie(-name=>"myval", -value=>$value);
print $query->header(-cookie=>$cookie_out);

at the same site/ domain , how do i check the value in the myval cookie using php ? whats the php code example to read a cgi cookie ?

Cookie Problem!
I have a huge problem with my php cookies in a login script. When a user logs out I instruct my script to unset the cookie and load the login screen as so. PHP Code:

Cookie Issue
I want my script to only work if the user has cookies enabled for his/her browser. How do I do this? Is there a way I could get information about the user's browser settings?

Cookie Problem
you goto a page and vote. the script then sets a cookie to prevent users from voting again... the problem though is that the cookies expiration wont work... anyway, PHP Code:

Cookie In Frame
I have this login that works fine when the page is presented as-is, but
I want to allow other site owner to put any page from my site in a
frame in their own site.

The thing is that when the page is called from a different domain, the
cookie is not sent to the server.

Cannot Expire Cookie
I am having problems expiring cookies in PHP, i.e. when you want to
logout of an application.

Has anyone had this problem, and what is the solution. Working code is
appreciated.

Cookie Problem
I try to have my message board set cookies so that users don't have to use their usernames and passwords each time. This is the code I have: Code:

$year=time() + 3153600000;
setcookie(cookieusername5, $sender, $year);
setcookie(cookiepassword5, $password, $year);

It works fine, the cookies are set. They canbe read with no problem. Until I close the browser window. When I come back again, the cookies are no longer set. What exactly am I doing wrong here?

PHP Cookie Information
How do I read the expiration time for a cookie? I understand that reading the value of a cookie is just $HTTP_COOKIE_VARS["CookieName"] but is there a way to read when it expires?

What I'm trying to do is make a login with a "remember me" option. So if you choose "remember me" the cookie is permanent, but if not it expires an hour after you are done with the admin section of the site.

So I need to keep updating the cookie to expire after an hour, but only if it is set to expire less than an hour from "now".

Cookie Newbie -- Please Help
I'm writing a discussion board app that will store a user's name in a
cookie after they log in so that for the duration of their visit to the
site and for a half hour afterwards, they will not have to log in again.
I realize that cookies must be sent in the header of a page before any
content, so on my 'write message' page, I have the following in the
header section, before even the doctype declaration:

Problem To Set A Cookie
I validate a user and set a cookie woht the following sentence:

setcookie("usNick",$nickN,time()+7776000);
setcookie("usPass",$passN,time()+7776000);

then I want to validate if the cookie is set with the following
sentence and it seems to enter in the "else", so the cookie was not
established.

if(isset($HTTP_COOKIE_VARS["usNick"]) &&
isset($HTTP_COOKIE_VARS["usPass"]))
{
$result = mysql_query("SELECT * FROM usuarios WHERE nick='".
$HTTP_COOKIE_VARS["usNick"]."' AND password='".
$HTTP_COOKIE_VARS["usPass"]."'");
}
else
{
setcookie("usNick","x",time()-3600);
setcookie("usPass","x",time()-3600);
}

Can anyone help me with this? I mean, setting the cookie correctly?

Cookie Spec
Anyone know where I can find info on the cookie spec? I seem to be having a
problem(after hours of narrowing it down) where I am using some special
characters that are not allowed in a cookie name or data.

What I'm essentially doing is encrypting the name/data then encoding it
using base64 but base64 uses the special characters +, /, and =. They seem
to be causing problems with the cook being written or read. I have mapped
the ='s into _ and can map the + into - because I think those work for
cookies but I am not sure... and then I have the issue with the /. (which
I'm thinking of using _ for it too but have to handle the case where it
occurs at the end of the string to be encoded(Which will cause it to be
confused with the padding).

Session Cookie
What happens when the the previous session cookie is not destroyed (but
session_destroy() and session_unset() have been used previously) apart
from the fact that the previous session id will be used. Does this mean
that the previous session only will continue?


Could this cause problems while logging in (assuming only the session
id is stored in the cookie and all the session variables are set again
on the checklogin page)?

Lost Cookie
I have problems with non persistent cookies in popup windows (window.open), sometimes the cookie are lost in the poup window.. that is when you try to get its value in the popup window ....at least in internet explorer 4, anyone has experienced a similar problem?


Copyright © 2005-08 www.BigResource.com, All rights reserved