473,804 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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()expe cts parameter 2 to be string object given in *.php
on line 21

21: while (!setcookie("US ER",$User, time()+3600)) {
22: $errmsg = $Unable_to_regi ster_txt;
23: LogMsg($errmsg) ;
24: if ($errcnt >= 3) {
25: $errmsg = $Unable_to_regi ster_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

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

Jul 17 '05 #1
3 3406
RotterdamStuden ts 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('displa y_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_regi ster_txt = 'Unable to register txt';
14 $Unable_to_regi ster_3_attempts _txt = 'Unable to register 3 attempts txt';
15 $errcnt = 0;
16
17 while (!setcookie("US ER", $User, time()+3600)) {
18 $errmsg = $Unable_to_regi ster_txt;
19 LogMsg($errmsg) ;
20 if ($errcnt >= 3) {
21 $errmsg = $Unable_to_regi ster_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('displa y_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_regi ster_txt = 'Unable to register txt';
14 $Unable_to_regi ster_3_attempts _txt = 'Unable to register 3 attempts txt'; 15 $errcnt = 0;
16
17 while (!setcookie("US ER", $User, time()+3600)) {
18 $errmsg = $Unable_to_regi ster_txt;
19 LogMsg($errmsg) ;
20 if ($errcnt >= 3) {
21 $errmsg = $Unable_to_regi ster_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("US ER", $User, time()+3600)) {

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

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

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

while (!setcookie("US ER", $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
11320
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 ($hasLoggedIn && ($row = mysql_fetch_row($query))) { setcookie('nordicnet_registration', $row, 0, '/'); @mysql_free_result($query);
5
6464
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 sent by (output started at D:\Apache Group\Apache2\htdocs\YC\songs.php:4) in D:\Apache Group\Apache2\htdocs\YC\ycphpfunc.php on line 148 My .php file looks like this:
6
2078
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 has something like this: <?php setcookie('code',$value, time + $lifetime, '/', '.example.com'); ?>
3
2299
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 encountered this, but without any luck, so I now resolve to pose the question myself. Code: <?php $somedata="Lorem Ipsum";
6
2676
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, or how I trace them? Also, I created cookies using this command: $string_to_check = $type."_".$pid; setCookie("$string_to_check", "1", time()+30*1); The cookie doesn't expire in 30 seconds - in fact, it doesn't seem to expire at all.
9
2298
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." 4. Display last modified date of doc. Here is my attempt. What a headache :-(
8
5873
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 checked to make sure that the variables have values and that the proper expire time is set and etc. Any ideas? <?php foreach($_POST as $name => $value){ if($name == 'hItem'){ $item = $value;
9
26261
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 than a function to set and retrieve the cookie but still nothing. Why is this happening?
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10564
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10073
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9134
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.