473,468 Members | 1,525 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems setting cookie

Hi!
I wrote a small script setting a cookie.... but nothing is being set.
What could be the problem?! Did I make something wrong?! One script is
used to ask for the cookie and the other one shows the displayed
variable in a string only! But if I look at Firefox in the cookie cache
if the variables are set... I didn't find anything. what could be the
problem?!

Apache 2.0.54 with PHP 5.1 RC1 on Gentoo Linux 2005.1

For any help... Thanks in advance

Tamer
1st Script: Abfrage.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<?
ob_start();
?>
<html>
<head><title>Registrierungsformular</title>
<link rel="stylesheet" href="eigenschaft.css" type="text/css">
</head>
<body>
<center>
<?
if (isset($_POST["register"]) && ($_POST["register"] == 'Abschicken!')
&& ($uid = check_auth($_POST["Login"],$_POST["Passwort"])))
{
setcookie('uid',$uid,time() + 14400,'/');
header('Location: http://localhost/~tamer/Anmeldung.php');
exit();
} else {

?>
<h1>Hallo... dies ist ein Test!</h1>
<form method="POST" action="Anmeldung.php">
<table>
<tr>
<td>Login: </td>
<td><input type='text' name="Login"></td>
</tr>
<tr>
<td>Passwort: </td>
<td><input type='password' name="Passwort"></td></tr>
<tr><td><input type="submit" name="register" value="Abschicken!"></td></tr>
</table>
</form>
</center>
<?
}
?>
</body>
</html>

2nd Script: Registrierung.php:

<?
$login = $_REQUEST["Login"];
$Passwort = $_REQUEST["Passwort"];

print "Mein Login ist: $login und das Passwort ist: $Passwort";
?>
Sep 16 '05 #1
4 1600
Tamer Higazi wrote:
Hi!
I wrote a small script setting a cookie.... but nothing is being set.
What could be the problem?! Did I make something wrong?! One script is
used to ask for the cookie and the other one shows the displayed
variable in a string only! But if I look at Firefox in the cookie cache
if the variables are set... I didn't find anything. what could be the
problem?!

Apache 2.0.54 with PHP 5.1 RC1 on Gentoo Linux 2005.1

For any help... Thanks in advance

Tamer


http://www.php.net/manual/en/function.setcookie.php

"setcookie() defines a cookie to be sent along with the rest of the HTTP
headers. Like other headers, cookies must be sent before any output from
your script (this is a protocol restriction)."

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 16 '05 #2
Neither that!
even if I change the form method post and the whole script to "GET"
instead of "POST", I still receive no cookie!
Jerry Stuckle wrote:
Tamer Higazi wrote:
Hi!
I wrote a small script setting a cookie.... but nothing is being set.
What could be the problem?! Did I make something wrong?! One script is
used to ask for the cookie and the other one shows the displayed
variable in a string only! But if I look at Firefox in the cookie
cache if the variables are set... I didn't find anything. what could
be the problem?!

Apache 2.0.54 with PHP 5.1 RC1 on Gentoo Linux 2005.1

For any help... Thanks in advance

Tamer


http://www.php.net/manual/en/function.setcookie.php

"setcookie() defines a cookie to be sent along with the rest of the HTTP
headers. Like other headers, cookies must be sent before any output from
your script (this is a protocol restriction)."

Sep 16 '05 #3
Tamer Higazi wrote:
Neither that!
even if I change the form method post and the whole script to "GET"
instead of "POST", I still receive no cookie!


That's because you're sending output before the call to setcookie()!

Makes no difference if it's GET or POST - you cannot send ANYTHING - no
blank line, no nothing - before a call to setcookie().

Fix you code and it will work just fine!

P.S. Please don't top post.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 17 '05 #4
Tamer Higazi wrote:
Neither that!
even if I change the form method post and the whole script to "GET"
instead of "POST", I still receive no cookie!


P.S. Turn on the error display and you'll see the problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 17 '05 #5

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

Similar topics

1
by: Stefan | last post by:
I am using the following code to set a cookie for 30 seconds: $value = $_GET; if (! isset($_COOKIE)){ setcookie('testit',$value,time()+30,'/'); } What happens: 1. On the windows apache server...
6
by: webhead74 | last post by:
Hi, I'm trying to move our web site from a Windows 2000 box running IIS / PHP CGI (4.0.6) to a RedHat box running Apache (actually IBM HTTP Server v2.0.47) & PHP 4.3.10. First of all, I...
2
by: bagsmode | last post by:
Hi, I'm trying to set a session cookie and then redirect, however I get the error: Status: 302 Moved Location: /index.cgi I thought I recall getting an error like this when I first tried...
8
by: Marc Hoeve | last post by:
Hi everybody I'm setting up 2 websites for a friend of mine, en I'm have problems with one of the sites. The situation: I have 2 different domains (both in the .NL domain). Both domains...
1
by: Jose Olivas | last post by:
I am setting a cookie on a subdomain: http://store1.mydomain.com Then the store takes me to a shopping cart that is at: http://shopping.mydomain.com Somewhere the following code (taken and...
3
by: Justin Morris via DotNetMonster.com | last post by:
<asp:TextBox ID="TextBox1" runat="server" value='<%=Server.HtmlEncode (Request.Cookies("Username")("Username"))%>'/> <input name="Password" type="text" id="Password" value='<%...
2
by: Alan Silver | last post by:
Hello, I have discovered that if I try and add a cookie when one by that already exists, nothing happens. No error, but the cookie is not set to the new value. For example (this is running in...
4
by: SevDer | last post by:
Hi, I've done some coding in my web application however right now for an unknown reason my asp.net 2.0 site is not setting asp.net_sessionid cookie and as a result, I am losing the session data...
5
by: sophie_newbie | last post by:
Does anyone know how to do this? I can't seem to make it work. I'm using: c = Cookie.SimpleCookie() c = "unamepwordwhatever" c.expires = time.time() + 300 print c
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.