473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Setcookie fault

For registering a user to one of my sportleagues i use a little part of
undeneath script to set a cookie. but this returns the next fault when a new
user registers:

Warning: setcookie()expects parameter 2 to be string object given in *.php
on line 21

21: while (!setcookie("USER",$User, time()+3600)) {
22: $errmsg = $Unable_to_register_txt;
23: LogMsg($errmsg);
24: if ($errcnt >= 3) {
25: $errmsg = $Unable_to_register_3_attempts_txt;
26: LogMsg($errmsg);
27: break;
28: }
29: $errcnt++;
}

The user is registered even when he gets the fault.
Waht's wrong with above part of script.

Thanks in advance

--
RotterdamStudents
-------------------------------
Dulce est despirere loco
(Horatius, "Oden" 4,12,28)

Jul 17 '05 #1
3 3382
RotterdamStudents wrote:
Waht's wrong with above part of script.


I see nothing wrong with above part of script. Your error must be from
before line 21.

Try this:

1 <?php
2 error_reporting(E_ALL);
3 ini_set('display_errors', '1');
4
5 function LogMsg($txt) {
6 echo '=== LOG === ', date('Y-m-d H:i:s'), "\n";
7 echo $txt, "\n\n";
8 }
9
10 header('Content-Type: text/plain charset=us-ascii');
11 echo "error here\n";
12 $User = 'me';
13 $Unable_to_register_txt = 'Unable to register txt';
14 $Unable_to_register_3_attempts_txt = 'Unable to register 3 attempts txt';
15 $errcnt = 0;
16
17 while (!setcookie("USER", $User, time()+3600)) {
18 $errmsg = $Unable_to_register_txt;
19 LogMsg($errmsg);
20 if ($errcnt >= 3) {
21 $errmsg = $Unable_to_register_3_attempts_txt;
22 LogMsg($errmsg);
23 break;
24 }
25 $errcnt++;
26 }
27
28 echo "All done\n";
29 ?>

then remove (or comment out) line 11 and try again.

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
> I see nothing wrong with above part of script. Your error must be from
before line 21.

Try this:

1 <?php
2 error_reporting(E_ALL);
3 ini_set('display_errors', '1');
4
5 function LogMsg($txt) {
6 echo '=== LOG === ', date('Y-m-d H:i:s'), "\n";
7 echo $txt, "\n\n";
8 }
9
10 header('Content-Type: text/plain charset=us-ascii');
11 echo "error here\n";
12 $User = 'me';
13 $Unable_to_register_txt = 'Unable to register txt';
14 $Unable_to_register_3_attempts_txt = 'Unable to register 3 attempts txt'; 15 $errcnt = 0;
16
17 while (!setcookie("USER", $User, time()+3600)) {
18 $errmsg = $Unable_to_register_txt;
19 LogMsg($errmsg);
20 if ($errcnt >= 3) {
21 $errmsg = $Unable_to_register_3_attempts_txt;
22 LogMsg($errmsg);
23 break;
24 }
25 $errcnt++;
26 }
27
28 echo "All done\n";
29 ?>

then remove (or comment out) line 11 and try again.


Using your script i still get the fault in the line:

while (!setcookie("USER", $User, time()+3600)) {

it's a parse error: Parse error: parse error in /php/CreateUser.php

--
RotterdamStudents
-------------------------------
Dulce est despirere loco
(Horatius, "Oden" 4,12,28)

Jul 17 '05 #3
RotterdamStudents wrote:
Using your script i still get the fault in the line:

while (!setcookie("USER", $User, time()+3600)) {

it's a parse error: Parse error: parse error in /php/CreateUser.php


Are you sure you didn't change anything in my script? :)

I can't reproduce a "parse error".
I can reproduce a similar message by changing line 12 to

$User = array(1, 2, 3, 4);

The exact error message I get is:
setcookie() expects parameter 2 to be string, array given
in /var/www/debug/xx.php on line 17
Other than that I see one small error in my script:
On line 10, there should be a semicolon between the text/plain and the
charset (I wonder how it disappeared -- computers are strange beasts :)

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Phil Powell | last post by:
Fourth attempt.. it fails now in login, I check by printing $_COOKIE and there is no value there! Guys, what on earth do I do about this???? Here is the code that sets the cookie: if...
5
by: Ben | last post by:
Hi all, In my .php file, I'm using both session_start() and setcookie() before <html> tag. It gives me following warning message: Warning: Cannot modify header information - headers already...
6
by: GregoryD | last post by:
I'm going to try to simplify this issue as much as possible. In my public_html/ directory, I have a login script that sets a cookie to be used for authentication purposes. To set the cookie, it...
3
by: Cmaza | last post by:
Hi, I've been dealing with PHP for a few years now and I've never encountered a problem quite like this. I've searched the net for an answer to my problem hoping somebody else may have...
6
by: knkk | last post by:
I am not able to locate the cookies created by the setCookie function. They are not in the standard IE folder where temporary Internet files and cookies are placed. Does anyone know where I search,...
9
by: LayneMitch via WebmasterKB.com | last post by:
Hello. Got another one for you folks. I'm working on this problem that wants me to 1. Prompt for name 2. Use pop-up box with name 3. Display current date on page in format "October 30, 2000."...
8
by: SupraFast | last post by:
I have two hosting accounts. On one, my setcookie script works fine; cookies are created. On the other, the same script doesn't work. The function returns TRUE, but no cookies is created. I...
9
by: wangers16 | last post by:
Hi, I am quite new to PHP and recently I have been attempting to create a login script, just one problem, the setcookie function isn't working. I have tried a basic php file with nothing other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.