473,396 Members | 2,014 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,396 software developers and data experts.

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 1598
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
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...
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...

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.