News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Connect error

Started by -Kia-, April 23, 2007, 08:53:34 PM

Previous topic - Next topic

-Kia-

Beware, the wonder girl, only 14 years old, is attempting to code. And she can't do it.  >:(


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/xariax/public_html/sim/index.php:2) in /home/xariax/public_html/sim/connect.php on line 20

index:
<?php

include('connect.php');

if(
$loggedin == '0')
{
if(isset(
$_POST['submit']))
{

// Make sure all forms were filled out.

if((!isset($_POST['username'])) || (!isset($_POST['pass']))
|| (
$_POST['username'] == '') || ($_POST['pass'] == ''))
die(
"Please fill out the form completely. <br><br>
<a href=index.php>Continue</a>"
);

// Get user's record from database
$player = @mysql_query("SELECT id, username, password, registered, lastlogin FROM players WHERE username = '".$_POST['username']."'");
$player = @mysql_fetch_assoc($player);

if(
$player['id'] == false)
die(
"Sorry, that user is not in our database.<br><br>
<a href=index.php>Back</a>"
);
else if(
$player['password'] != md5($_POST['pass']))
die(
"Wrong password!<br><br>
<a href=index.php>Back</a>"
);

// set session variables
$_SESSION['id'] = $player['id'];
$_SESSION['username'] = $player['username'];
$_SESSION['password'] = $player['password'];

// update last login
$date date("m/d/y");

$update = @mysql_query("UPDATE players SET lastlogin = '$date' WHERE id = '".$_SESSION['id']."'");

echo 
'You are now logged in!';

}
else
{
echo 
'You are not logged in. <br><br>
<form action=index.php method=post>
Username: <input type=text name=username><br>
Password: <input type=password name=pass><br>
<input type=submit name=submit value=Submit>
</form>
Would you like to <a href=register.php>register?</a>'
;
}
}
else
{
echo 
'You are logged in!
Welcome to my game, '
.$_SESSION['username'].'!
<br><br>
<a href=logout.php>Click Here to Logout</a>'
;

}

?>


Connect:
<?php

// This script will connect the user to your mySQL database.
// It will also check it they're logged in or not.
// It should be included on every page you create.

// Set the variables below to match your settings
$dbhost 'localhost';
$dbuser 'blank';
$dbpass 'blank';
$dbname 'blank';

$link mysql_pconnect($dbhost$dbuser$dbpass)
or die(
"Could not connect to server.");
$selectdb mysql_select_db($dbname$link)
or die(
"Could not connect to database.");

// Check to see if user is logged in

session_start();

if((!isset(
$_SESSION['id'])) || (!isset($_SESSION['username'])) ||
(!isset(
$_SESSION['password'])))
{
unset(
$_SESSION['username']);
unset(
$_SESSION['password']);
unset(
$_SESSION['id']);

$loggedin 0;
}
else
{
$loggedin 1;
}

?>


What's causing this error?  :'( I worked hard to get here and it's not working.

Also, how can I put this in a layout? I don't know how I would intertwine HTML in with PHP to get the login box in a table, ect.

Page:
hxxp:caninecountry.exofire.net/sim/ [nonactive]

-Kia-


Advertisement: