• Welcome to Valhalla Legends Archive.
 

[PHP] setcookie() error

Started by j0k3r, February 25, 2004, 05:40 PM

Previous topic - Next topic

j0k3r

Ok I'm trying to set a cookie to remember the user has logged in, which will enable him to do things on the site, but I get an error that claims I have text being outputted before the cookie is set, when this is clearly not the case, anyways code+error.

<?php$name = $_POST['name'];$password = $_POST['password'];include 'somedatabasefile.php';function verifylogin ($nametesting, $passwordtesting){   global $verified;   $verified = false;   $result = mysql_query("SELECT * FROM users;");      while ($row = mysql_fetch_array($result))    {      if ($nametesting == $row[0] && $passwordtesting == $row[1])      {         $verified = true;      }   }}verifylogin($name, $password);if (!is_null($name) && !is_null($password) && $verified){   setcookie("userid", "$name"); }mysql_close($dbh)?>

Warning: Cannot modify header information - headers already sent by (output started at /some/path/public_html/somedatabasefile.php:7) in /home/template/public_html/login.php on line 25

What's the problem?
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

Adron

Hmm, so what's in somedatabasefile.php? It doesn't start the output going?

j0k3r

#2
It says it started in somedatabasefile's line 7, well here's the code for that too.
<?php$dbh=mysql_connect ("place", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("somedatabase");?>


[edit]The reason I do it like this is because I do alot of this stuff at school, and I don't want people peeking at my username/password for the database.
[/edit]
[edit2]For those of you who are slightly interested, here's all you need to know about PHP and cookies. http://ca2.php.net/manual/en/function.setcookie.php[/edit2]
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

j0k3r

I came back an hour later, and it works, maybe I wrote some sort of self-writing code?
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

drivehappy

I prefer to use $_SESSION[], it is much easier.

j0k3r

Quote from: drivehappy on February 28, 2004, 08:04 PM
I prefer to use $_SESSION[], it is much easier.
But I need this to work for next time they visit the site, which means they could close the browser/restart the computer/whatever and it needs to still work. Not very nice having to sign in every time or keep your browser open 24/7 is it?
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

Banana fanna fo fanna

Quote from: j0k3r on February 25, 2004, 09:53 PM
I came back an hour later, and it works, maybe I wrote some sort of self-writing code?

That's BAD.

j0k3r

Quote from: St0rm.iD on February 28, 2004, 09:10 PM
Quote from: j0k3r on February 25, 2004, 09:53 PM
I came back an hour later, and it works, maybe I wrote some sort of self-writing code?

That's BAD.
Not for me, I'm it's creator, it won't turn on me.







Right?
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

Banana fanna fo fanna

PHP was invented by Europeans. Watch out.

j0k3r

So? I created it's intelligence.
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo