By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,819 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,819 IT Pros & Developers. It's quick & easy.

Setcookie fault

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
> 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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.