Jump to content

[SOLVED] Session Help..


clanstyles

Recommended Posts

Here ill post it all but config info.

 

login.php

<?php
include("header.php");
if (!$_SESSION['entered'])
{

	$errror = false;
	if(isset($_POST['submit']))
	{
		$result = mysql_query("select * from accounts");
		while($res = mysql_fetch_array($result))
		{
			if(strtolower($_POST['username']) == strtolower($res['username']) && md5($_POST['password']) == $res['password'])
			{	
				echo $username;
				echo $password;
				$_SESSION['uname'] = $_POST['username'];
				$_SESSION['pass'] = $_POST['password'];
				$_SESSION['entered'] = true;
				echo "done";
				echo "<br />";
				break;
			}
			else
			{
				$_SESSION['entered'] = false;
				echo "bad login";
			}

		}
			if($_SESSION['entered'])
				header("Location: main.php");

	}
	else 
	{
		echo "<center>";
?>

		<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>" id="submit">
		Username: <input type="text" name="username" size="16" /><br />
		Password: <input type="password" name="password" size="16" /><br />
		<div align="center">
		<p><input type="submit" value="Login" id="submit" name="submit" /></p>
		</div>
		</form>

		</center>

<?php	
	}
}
else 
{
			echo "<a href=\"" . session_destroy() . "\">Logout</a>";
			echo "<br /><a href=\"main.php?" . SID . "\">main</a>";
}
include("footer.php");	
?>

 

header.php

<?php
include("config.php");
?>
<html>
<header>
<title>
Technicolor Panel
</title>
</header>
<body>
<?php 
session_start();
?>

 

config.php

<?php
/* Defines for Datase Connection */
$hostname = "xxxxx";
$username = "xxxxx";
$password = "xxxxx";
$database = "xxxxx";

/* Connection String Start */
mysql_connect($hostname, $username, $password) or die(mysql_error());

/* Select Database */
mysql_select_db($database);
?>

 

main.php

<?php
include("header.php");

if (!$_SESSION['entered'])
{
	echo "haha doesn't work.";
}
else 
{
	echo "Works nice...";
	echo "<br /><a href=\"login.php?" . SID . "\">main</a>";
}

include("footer.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-279409
Share on other sites

In header.php you are calling session_start() when you have outputted HTML. You cannot call session_start() when any form of output has been made.

 

I recommend you to add session_start() as the first line in login.php and main.php. Remove session_start from header.php. You don't need it in header.php as you are including this file.

Link to comment
https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-280807
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.