I’m new to php and have been trying to teach myself for the last few months. I had a site completely finished through a test url and everything including php pages that talked to my mysql database worked perfectly. Yesterday I put the site on it’s intended url and now my back end admin pages are not working. I imported the original database and changed all the needed names for my connection page. What appears to be the problem is that session_start is conflicting with header commands. These are the errors that I get.
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/64/7074664/html/pages/logver.php:1) in /home/content/64/7074664/html/pages/logver.php on line 28
Warning: Cannot modify header information - headers already sent by (output started at /home/content/64/7074664/html/pages/logver.php:1) in /home/content/64/7074664/html/pages/logver.php on line 30
and this is my code for logver.php:
<?php
include "connect.php";
echo "<div class='thanks'>";
$user = $_POST['myusername'];
$pass = $_POST['mypassword'];
if($user&&$pass)
{
mysql_connect($hostname, $username,$password )or die("can't connect");
mysql_select_db($dbname) or die("Couldn't find DB");
$sql = "SELECT * FROM users WHERE `username`='".$user."'";
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
if ($numrows!=0){
while($row = mysql_fetch_assoc($result))
{
$dbuser = $row['username'];
$dbpass = $row['password'];
}
if($user==$dbuser&&$pass==$dbpass){
session_start();
session_register('varUser');
header ("Location: admin_page.php");
}else{
include "login.php";
echo "That password is incorrect";
}
}else{
include "login.php";
die ("That user doesn't exist");
}
}
else{
include "login.php";
die ("Please enter username and password");
}
echo "</div>";
?>
I do have a small css style that proceeds this, but when I tried to take it out it actually led to more confusion (which I may have to fix on another page later), so it’s left in for now.
As I understand my session_start may need to be at the top of the page? I’ve tried this but it hasn’t helped me any. Besides I don’t see how I can start the session before I’ve entered the username and password?
Why might this work perfectly on my test site and not on the actual site?
Any help here would be much appreciated.
Thanks