Location: PHPKode > projects > Blackbeard's Revenge > login.php
<?php
session_start(); 
header("Cache-control: private");

require_once "headers.php";
require_once "common.php";

if($_GET["login"])
{
	if($DEBUG) echo "get login<br>";
	$playername = $_POST["name"];
	$playerpassword = $_POST["password"];

	/* Connecting, selecting database */
	//$link = db_pconnect($DB_HOST, $DB_USER, $DB_PASS);
    //db_select_db($DB_NAME);
		/* Performing SQL query */
		//$query = "SELECT * FROM players WHERE name='". $playername ."'";
		$query = "SELECT uid, password FROM players WHERE players.name = '". $playername ."'";
		if($DEBUG) echo $query;
		if($DEBUG) echo "<Br>";
		$result = db_query($query);
		if($DEBUG) echo "query() = ". $result ."<br>";
		$row = db_fetch_assoc($result);
		//$_SESSION[user]=db_fetch_assoc($result);
		if($DEBUG) echo "result() = ". $row ."<br>";
			
		if($row["password"] == $playerpassword)
		{
			if($DEBUG) echo "<br>Password is good";
			//do login
			$message = "Logging you in";
			//$_SESSION[user] = array();
			LoadPlayer($row["uid"]);

			//$_GET["login"] = 0;

			/*$_SESSION['uid']            = $_SESSION[user]["uid"];
			$_SESSION['playername']     = $_SESSION[user]["name"];
			$_SESSION['mycharisma']     = $_SESSION[user]["charisma"];
			$_SESSION['mygunnery']      = $_SESSION[user]["gunnery"];
			$_SESSION['mysailing']      = $_SESSION[user]["sailing"];
			$_SESSION['mycountry']      = $_SESSION[user]["country"];
			$_SESSION['mygender']	    = $_SESSION[user]["sex"];
			$_SESSION['playerlevel']    = $_SESSION[user]["level"];
			$_SESSION['myage']		    = $_SESSION[user]["age"];
			$_SESSION['experience']	    = $_SESSION[user]["experience"];
			$_SESSION['playergold']     = $_SESSION[user]["gold"];
			$_SESSION['playermaps']     = $_SESSION[user]["maps"];
			$_SESSION['myshipname']     = $_SESSION[user]["shipname"];
			$_SESSION['myshipvalue']    = $_SESSION[user]["value"];
			$_SESSION['myshipclass']    = $_SESSION[user]["classname"];
			$_SESSION['myshipimage']    = $_SESSION[user]["shipimage"];

			$_SESSION['myshipcrew']     = $_SESSION[user]["crew"]; 
			$_SESSION['myshipmanuver']  = $_SESSION[user]["manuver"]; 

			$_SESSION['myshiptype']     = $_SESSION[user]["shiptype"]; 
			$_SESSION['playershipnum']  = $_SESSION[user]["shiptype"];
			$_SESSION['myshiphull']     = $_SESSION[user]["hull"];
			$_SESSION['mycannons']      = $_SESSION[user]["cannon"];
			$_SESSION['myarmor']        = $_SESSION[user]["armour"];*/
			
			//If newday then give more turns
			//$_SESSION[user]["turns"] = 10;

			/*$query = "UPDATE players SET 
			    turns = ".$_SESSION['turns'].",
				lastip = '".$_SERVER['REMOTE_ADDR']."',
				lastlogin = '".date("Y-m-d H:i:s",strtotime("-1 day"))."'
				WHERE uid=". $_SESSION['uid'] ." ";
			$result = db_query($query);
			if($DEBUG) echo "query() = ". $result ."<br>";*/
			
			LoadShips();
			
			echo "<script>if (top.location != location) {top.location.href = document.location.href;}</script>";
			echo "<META HTTP-EQUIV=\"refresh\" content=\"1;URL=index.php?module=2\" target=_top\">";
		}
		else
		{
			if($DEBUG) echo "<br>Password is not good";
			echo "password incorect";

			$message = "Password incorrect";
			DisplayLogin();
		}
		/* Free resultset */
		//db_free_result($result);
	/* Closing connection */
	//mysql_close($link);
}
else
{
	$message = "Please login";
	DisplayLogin();
}

DisplayMessage($message);


function DisplayLogin()
{
	print "<form action=\"login.php?login=1\" method=\"POST\">";
	print "<table class=\"menu\" border=0>";
	print "	<tr><td class=\"menuheader\" colspan=3>Login</td></tr>";
	print "	<tr><td colspan=2><div align=center><table class=\"data\" border=0>";
	print "	<tr><td class=\"header\" colspan=3>Name</td></tr>";
	print "	<tr><td colspan=2 class=\"body\"><input type=\"text\" name=\"name\" class=\"login\"></td></tr>";
	print "	<tr><td colspan=2 class=\"body\"><input type=\"password\" name=\"password\" class=\"login\"></td></tr>";

	print "<tr>";
	print "<td><input class=\"button\" type=\"Submit\" name=\"submit\" value=\"Login\"></form></td>";
	print "<td><form action=\"chargen.php\" method=\"POST\"><input class=\"button\" type=\"Submit\" name=\"submit\" value=\"Create\">";
	print "<input type=\"hidden\" name=\"login\" value=1>";
	print "<input type=\"hidden\" name=\"firsttime\" value=1>";
	print "</tr>";

	print "</table></form>";
}

function processNation()
{	
	//Process starting gold per nationality
	//English
	if($_SESSION['mycountry'] == 1) {
		$_SESSION['playershipnum'] = 1;
		$_SESSION['myshipname']    = "HMS Defiant";
		$_SESSION['playergold']    = 6000;
		$_SESSION['playermaps']    = 3;}
	//Spanish
	else if($_SESSION['mycountry'] == 2) {
		$_SESSION['playershipnum'] = 2;
		$_SESSION['myshipname']    = "Santa Maria";
		$_SESSION['playergold']    = 60000;
		$_SESSION['playermaps']    = 10;}
	//French
	else if($_SESSION['mycountry'] == 3) {		
		$_SESSION['playershipnum'] = 2;
		$_SESSION['myshipname']    = "Aventure";
		$_SESSION['playergold']    = 5000;
		$_SESSION['playermaps']    = 5;}
	//Dutch
	else {		
		$_SESSION['playershipnum'] = 1;
		$_SESSION['myshipname']    = "Rondtrekken";
		$_SESSION['playergold']    = 25000;
		$_SESSION['playermaps']    = 2;}

	//ship info	 
	$_SESSION['myshipclass']   = $_SESSION[ships]['ShipName'][$_SESSION['playershipnum']];
	$_SESSION['myshiphull']    = $_SESSION[ships]['ShipBaseHull'][$_SESSION['playershipnum']];
	$_SESSION['myshipmaxhull'] = $_SESSION[ships]['ShipBaseHull'][$_SESSION['playershipnum']];
	$_SESSION['mycannons']     = $_SESSION[ships]['ShipBaseCannon'][$_SESSION['playershipnum']];
	$_SESSION['myarmor']       = $_SESSION[ships]['ShipBaseArmour'][$_SESSION['playershipnum']];
}

?>
Return current item: Blackbeard's Revenge