I have the following code:

<?php
include("localsettings.php");
// Grab login info
if ((!empty($_POST['username'])) && (!empty($_POST['password']))) {
  $username = $_POST['username'];
  $pass = $_POST['password'];
  if (!empty($_POST['rememberme'])) {$rememberme = $_POST['rememberme'];}else{$rememberme = "";} // Will be 1 if checked and nothing if not
  $hashedpass = hash('sha256', $pass); // Hash with sha256
  if (file_exists("users/" . $username . ".txt")) {
    $filepass = file_get_contents("users/" . $username . ".txt");
	if ($filepass == $hashedpass) {
	  if ($rememberme = 1) {
        setcookie('username', $username, time()+60*60*24*365, '/', $server);
        setcookie('password', $hashedpass, time()+60*60*24*365, '/', $server);
	  } else {
	    setcookie('username', $username, false, '/', $server);
        setcookie('password', $hashedpass, false, '/', $server);
	  }
	  print_r($_COOKIE);
      //header ('HTTP/1.1 301 Moved Permanently');
      //header ('Location: ' . $site);
	} else {
	  // Right username, wrong pass
	  echo ("Icorrect Password. <a href=\"" . $site . "/index.php?title=Special[UserLogin]\">Try Again</a>?");
	}
  } else {
	// Wrong Username
    echo ("Incorrect Username. <a href=\"" . $site . "/index.php?title=Special[UserSignup]\">Signup</a>?");
  }
} else {
  header ('HTTP/1.1 301 Moved Permanently');
  header ('Location: ' . $site . '/index.php?title=Special[UserLogin]');
}
?>

It outputs Array() even when passed a username and password from a different page. The reason for the weird links is I am creating a CMS for my site.

    Where is $server ever defined? (And how is it defined?)

    Also, how did you determine [man]setcookie/man fails? Upon logging in for the first time, I would expect $_COOKIE to be empty since no cookies have been received by the client yet. [man]setcookie/man only tells the server to send out a cookie with this request; you won't get it back until the next page load.

    EDIT: Also, is either display_errors or log_errors set to On and error_reporting set to E_ALL?

      $server is defined as 'localhost' in the localsettings.php. Wen I upload the final product to my server, i will change it to cole.freehostingcloud.com (It is a CMS replacement for my Mediawiki. (you can check it out at cole.freehostingcloud.com/s. I KNOW it isnt working because there is no cole@localhost cookie in the cookies dir on my hard drive

        Write a Reply...