PDA

View Full Version : cookie problems...PHP


boyzdynasty
04-27-2003, 10:01 PM
my config.php runs fine...*well...no errors were displayed*

config contains (only copy the significant part):
<?

function auth($username, $password) {

/* Connect to MySQL Server */
$link = dbConnect();

$crypt = md5($password);

$query = "SELECT userID FROM '$table' WHERE ssn = '$username' AND password = '$crypt'";

// Execute the query
$result = mysql_query($query);

// If we found a match...
if (mysql_num_rows($result) == 1) {
// Extract user ID from the results
$user = mysql_fetch_array($result);
$userID = $user['userID'];

} else {
// Otherwise set username to -1
$userID = -1;
}

print "UserID = " . $userID ;

/* Close link to MySQL */
mysql_close($link);


// Set cookie
setcookie('userInfo',$userID);

// Tell Flash that all is okay
//print "COOKIE = " . $_COOKIE['userID'];


// Return user ID
return $userID;
}

?>So I did the set cookie....Now after calling that file...I call on getID.php I get this weird print message
UserID = aValue
Warning: Cannot modify header information - headers already sent by (output started at config.php:90) in config.php on line 96
COOKIE['userInfo'] =

*COOKIE wasn't set?...i guess. That is why it is blank

line 96 in config.php is setcookie('userInfo',$userID);

here is what I have in getID.php
<?php

// Include config file
include('config.php');

// For testing...
$username = "test";
$password = "test";

if(!isset($username) || empty($username) || !isset($password) || empty($password)){

fail("UserName and/or PassWord not specify");
}

// Get userID
$user = auth($username, $password);

if($user > 0){

//print "&result=Okay";
//print "&message=UserID is " . urlencode($user);
print "COOKIE['userInfo'] = " . $_COOKIE['userInfo'];

}else{

fail("No Match Found");
}

?>
Any one knows why I'm getting that Warning about header stuff message?

boyzdynasty
04-28-2003, 12:19 AM
ok. I figured it out...but not sure if I understand why

I just change the position of where I had originally set the cookie.

this is where I put it instead
// If we found a match...
if (mysql_num_rows($result) == 1) {
// Extract user ID from the results
$user = mysql_fetch_array($result);
$userID = $user['userID'];

setcookie('userInfo',$userID);

}