cookies #2

  • Permalink
  • submit to reddit
  • Email
  • Follow


hi,

I have following problem.

I have a form wich I post to another php file there i want to store the data
form the form in a cookie.
code:

<?

foreach ($HTTP_POST_VARS as $key => $value) {



if($value=='ON')


{


setcookie("TestCookie","$key",time()+3600);

}



But it doens'n work. I have the following Error Warning: Cannot modify
header information - headers already sent by (output started at C:\Program
Files\Apache Group\Apache2

I understand the error and i have search in de tutorial form php.net, but
How can I handle this problem?



Thanks,



Alain




0
Reply alain.dhaene1 (15) 1/11/2004 1:44:05 PM

See related articles to this posting

Alain Dhaene wrote:

> hi,
> 
> I have following problem.
> 
> I have a form wich I post to another php file there i want to store the data
> form the form in a cookie.
> code:
> 
> <?
> 
> foreach ($HTTP_POST_VARS as $key => $value) {
> 
> 
> 
> if($value=='ON')
> 
> 
> {
> 
> 
> setcookie("TestCookie","$key",time()+3600);
> 
> }
> 
> 
> 
> But it doens'n work. I have the following Error Warning: Cannot modify
> header information - headers already sent by (output started at C:\Program
> Files\Apache Group\Apache2
> 
> I understand the error and i have search in de tutorial form php.net, but
> How can I handle this problem?
> 
> 
> 
> Thanks,
> 
> 
> 
> Alain
> 
> 
> 
> 

You must set cookies before sending any other output to the browser... 
including spaces, line feeds, etc.

Move your code that does cookies to the top of your PHP file.  Maybe 
that'll help ya.

Regards,

- Dan
http://www.dantripp.com/
0
Reply thisIsNot (92) 1/12/2004 12:36:00 AM
comp.lang.php 32477 articles. 6 followers. Post

1 Replies
56 Views

Similar Articles

[PageSpeed] 24

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

cookies #2 #2
hello folks. PPC 10.5 Safari 5.0.6 is set to never accept cookies and as I'm watching the cookies window and going between sites on 10.5 a google cookie keeps popping up. Anyone know why this is happening? It seems it's being sent to my browser every so many minutes after I delete it. I set database storage to none and it's still popping up in the cookie window. Regards In article <0001HW.CAA3FCEA0032597CF01846D8@unlimited.newshosting.com>, Whitey Black <whiteyblack562@aol.com> wrote: > hello folks. PPC 10.5 Safari 5.0.6 is set to never accept cookies and a...

Session Cookie Glitch with mod_perl 2.03 and Apache 2.2.6
I have an application originally written for the combination of Apache 1.3.31, mod_perl 1.39, and MySQL 4.0.16 that I'm moving to new servers so I wanted to take the opportunity to migrate these components to the latest versions: Perl v5.8.8 built for i586-linux-thread-multi Apache 2.2.6 mod_perl 2.0.3 OpenSSL 0.9.8g libapreq 2-2.08 MySQL 5.0.45 The APIs for mod_perl changed substantially between 1.0 and 2.0 so I've gone through the code that involves the old 1.0 vintage Apache::xxxxxx modules and updated them to 2.0 equivalents in the Apache2::xxxxxx or ModPerl::xxxxxxx modules. Th...

[5.2.2/cURL] Not getting cookies?
Hello So I'm trying to use cURL to write a PHP5 script that is effectively a proxy, since the browser will call this index.php which will fetch pages from a remote server, and pass them on to the browser, including cookies. For some reason, cURL fails creating the file that holds cookies ("CookieJar not created!"), although I copy/pasted this code from cURL's web site (http://curl.haxx.se/libcurl/php/examples/cookiejar.html): ========= <?php //Using one script for different steps $status = ($_POST['status']? $_POST['status'] : $_GET['status'])...

cookie #2
What's the best I can do to solve my trouble : 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 '...

HELP: Konqueror cookie behavior changed after upgrade from 3.4.2 to 3.4.2
I'm a Gentoo user, and I just updated KDE from 3.4.2 to 3.4.3. I've noticed a change in cookie behavior. I like to read slashdot, and I like to stay logged in. Once I've logged in, I stay logged in for any article that is right off of slashdot.org. But for any subdomain, such as apple.slashdot.org, it appears that the right cookie isn't sent, so it makes me appear logged out. I've looked at the configuration menus for cookies, but I can't find a setting that would affect this. I also tried clearing out all cookies for slashdot.org, to no effect. Before I file a b...

your fortune cookie #2
you will have much good luck slek slke ai al owens lske s3 s lk339 akdn ali lkocn sonekslekwl. lskewqj iiao ...

cookie problem #2
Hi, I get the follow problem. A page is locate in C:\Directory\files\pag1.php There I call the function setUrl. (all the functions are located in C:\Directory\includes function setUrl() { var ckyDatum = new Date; ckyDatum.setDate(ckyDatum.getDate()+7); var href = document.location.href; the_cookie = escape(href); document.cookie = 'test=' + the_cookie + '; path=/;' ; alert(document.cookie); } This is OK : the alert results in ' test = C\Directory\files\pag1.php In a page located in C:\Directory\sub\pag5.php I call the function getUrl <script langu...

Cookies #2 223816
hi. is there a way to convert a FF/IE cookie into using it with mechanize? cuz, i want to login a site that uses recaptcha, and mechanize can't login that way, so i was thinking of using a cookie that would make the site think i was already logged in, skiping the login process.. is this possible? if yes, how can it be done? thanks in advance! wassup <wassupme@gmail.com> wrote: > hi. is there a way to convert a FF/IE cookie into using it with > mechanize? cuz, i want to login a site that uses recaptcha, and > mechanize can't login that way, so i was thinking of using a ...

Cookies #2 551905
Hi, I'm unable to get cookies working on my IIS 6 Server and IE6 browser. I'm using the latest version of Active Perl. I have a "home" page that runs a perl cgi script that creates a cookie and also tries to read it when the page is called again. I have a second page that calls the home page to simulate a second request for the home page. I assume that the second time the page is called the cookie should be present. The problem is that the cookie never seems to get created. Any ideas on what is wrong with either my approach or the syntax for creating the cookie? Here is...

setting 2 cookies
I need to set two cookies. One to be used for redirection and page loading, which i have now and works and a second one that is used to write information on a page. Both are to be set automatically when loading the page. The second will will set a company name like "Your company name". Then when the next page is loaded it will put "Your company name" on the webpage. And like I said before the first cookie is set for navigation purposes. Jose U can use 1 cookie with several 'name=value' pairs separated by '&' sign: document.cookie = 'f...

Cookie problem #2
Hi all, I have a problem. I am beginer in cookie-making. I make one, on my laptop, where I run a web server, I can use my cookie. It operates properly independently if I use IE or Firefox. However, I applied my PHP code on a Linux server, where an Apache web server run with a PHP interpreter. On a remote computer I wanted to access my cookie-enriched page. The cookie was saved locally in the cookie-directory of my browser, but it had no any value. I experienced the same in case of IE and Firefox. Could you send me any idea, what is the mistake? Thanx very much Zsolt Vamosi Zsolt w...

PHP and Cookies #2
I am having trouble retrieving cookie data using IE 7. I am using the following code to store the current date and user name into a cookie: <?php //($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat, $isdst) = localtime(); $localtime = localtime(); $localtime[5] += 1900; $date = $localtime[4]+1 . "-" . $localtime[3] . "-" . $localtime[5]; // retrieve cookie $visit = $_COOKIE['lastdate']; if ($visit=="") $visit = "0-0-0"; $userlogin = $_COOKIE['user']; if ($userlogin=="") $userlogin = "Guest"; // set cookie SetC...

Cookie Question #2
I wrote a small .php script that creates a cookie on my local PC - I also wrote one that deletes it. My question is this: when the cookie has been created and I run the delete .php script, when it first loads it does not delete the cookie - I always have to click on the browser refresh button - why doesn't the script execute on the first execution? Thanks... I'd suggest you have a further read on cookies and how they relate to intricacies of HTTP. It can get a bit tricky ;). Anyway. The PHP script wouldn't 'delete' the cookie from your computer, it simply sends a hea...

problem with cookies #2
Hi .. i have a problem .. i set a cookie with www.domain.com, and for some = reason if the user goes to my website at domain.com without the www, a cook= ie is set without the www, and i can no longer read the cookie with the www= ... why is this? what can i do? On Mon, 14 May 2012 19:08:23 -0700 (PDT), CODEY <ed.pataky@gmail.com> wrote: >why is this? www.domain.com and domain.com could be entirely separate systems, as are www.swifys.org.uk (on a commercial server somewhere) and swiftys.org.uk (on my home PC where I'm typing this) Cookies are typically recorded against th...

Cookies and PHP #2
I am looking to store a cookie on a client (machine) and then when the client revisits, to populate part of the form with data held on my server (ok this is for a my course). A I will need to get the initial data from the client. B Store it on my server with an account number. C Create a copy on the host or alternatively an account number. D When the user logs back on I will need to populate the form with the data they already entered. Any pointers or help appreciated. J James wrote: > I am looking to store a cookie on a client (machine) and then when the > client revisits, to ...

Sessions vs Cookies #2
I am working on a project that will eventually scale up to multiple servers and want to be sure I choose the correct path for controlling persistant information, for example a users ID. From what I have read, using sessions could limit me to a single server, where as cookies will allow me to have multiple servers as the persistant information travels with the client instead of residing on the server. Am I wrong in this assumption? Are there any best practices with dealing with persistant information and multiple servers? Bill H Bill H wrote: > I am working on a project that will eventuall...

Cookies and session variables #2
To find out were session variables are stored I included this instruction in my program: echo ini_get("session.save_path"); The reply was /home/7604/data/tmp which is a folder on my server. I look at /home/7604/data/tmp and it is full of session files for today. Even so, if I have cookies blocked for my site http://easyquestion.net in IE6 or cookies turned off in Mozilla Firefox no session variabes are stored. I don't think it should be like this. I read somewhere that 'PHP sessions will work even if the user has cookies disabled." What am I doing wrong? Regards, J...

PHP & Cookies #2
Hi, I'm having a problem with cookies in php. I set a cookie on one page, then when i try and read the cookie on another page, i have to refresh the browser to get the latest informaiton from the cookie. If i don't refresh the browser, the cookie returns old information. If I set the cookie, then close the browser, then try and read it, it works fine. Gareth Gareth Evans wrote: > Hi, I'm having a problem with cookies in php. I set a cookie on one page, > then when i try and read the cookie on another page, i have to refresh the > browser to get the latest informa...

3rd party cookie #2
Is it possible to check for the existence of a 3rd party cookie. I.e. Check if a cookie has been set from Google, Lycos etc. Hamish wrote: > Is it possible to check for the existence of a 3rd party cookie. No (unless a very badly written browser (neither FF nor IE). Hamish wrote: > Is it possible to check for the existence of a 3rd party cookie. > > I.e. Check if a cookie has been set from Google, Lycos etc. I know of no way to do this, mainly because I have never found it necessary. Various combinations of my XP OS sp2 and various recent browsers and security programs a...

How to capture cookies information #2
Hi, I am new to php scripting and want to find out how to capture cookies from user machines such as from Windows or linux machine. Thanks in advance. "xo55ox" a �crit le 08/12/2003 : > I am new to php scripting and want to find out how to capture cookies > from user machines such as from Windows or linux machine. Do you want to use "normally" cookies or do you want to "spy" on cookies from other sites? If it is normal cookie use go and see : http://fr2.php.net/manual/en/function.setcookie.php -- Have you read the manual? http://www.php.net/manual/en...

[HTTP] Cookie issue #2
Hello, I added the following directives to the Apache (1.3.20) configuration: Alias /temp C:/Temp <Location /temp> Header append Set-Cookie msg1=Hello;path=/test Header append Set-Cookie msg2=world;path=/test Options indexes </Location> When requesting /temp, the browser (IE6) gets a Set-Cookie directive with two cookies: HTTP/1.1 200 OK (...) Set-Cookie: msg1=Hello;path=/test, msg2=world;path=/temp (...) This looks correct, as per RFC 2109 - 4.2.2 Set-Cookie Syntax: " Informally, the Set-Cookie response header comprises the token Set- Cookie:, fol...

OffByOne: how to edit cookies? #2
Is there any way to edit the cookie file in OB1? All I can get it to do is view it, and it doesn't seem to be in standard ASCII so I can't just use a text editor. OB1 never answers support email, so I'm SOL trying to deal with them. -- _____________________________________________________ For email response, or CC, please email see.my.sig.4.addr-a@t-bigfoot.com. Yeah, it's really a real address :) ...

Get cookie expiry time #2
Hi, I am using cookies to keep track if a user is logged into my system, and would like to display the time that the user has left logged in. One solution is to display the time left until the cookie expires. Does anyone know how to retrieve the expiry time of a particular cookie? TIA Jeff If the above is not possible, then I suppose one solution is to store the expiry time in an additional cookie. On Tue, 02 May 2006 03:05:15 -0700, mymatebob wrote: > If the above is not possible, then I suppose one solution is to store the > expiry time in an additional cookie. Or re-set the c...

Re: Filename URL and Cookies #2
pchoate@DDS.CA.GOV wrote back: >Reading past posts I see the honorable David L. Cassell recommends PERL as >is usual, and also that there's a cool free app out there called cURL that >can be used with a filename pipe. Otherwise SAS filename URL doesn't >handle cookies. > >See >http://groups.google.com/group/comp.soft-sys.sas/search?group=comp.soft-sys.sas&q=curl+pipe You might be able to use the SOCKET engine and fake your own HTTP to get around this, but that is likely to be even ickier than the above suggestions. Oh, and the language is Perl. Just as we d...