Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.