PHP Problem

Hello. I made a website for an online game I play. It’s pretty basic blog site. Now my problem is, when I run the website on my localhost (I use WAMP for testing) everything works fine. When I put it on my server, the admin login part doesn’t work properly.
[php]<?php

mysql_connect(“localhost”,“root”,"");
mysql_select_db(“blog”);

?>

Login <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $password = $_POST['password']; $result = mysql_query("SELECT * FROM members WHERE name='$name' AND pass='$password'"); $num = mysql_num_rows($result); if($num == 0){ echo "User name and password do not match. Please try again"; } else { session_start(); $_SESSION['name'] = $name; header("Location: admin.php"); } } else { ?> Username:
Password:
<?php } ?> [/php]

It logs me in and stuff, but it doesn’t redirect to admin.php header(“Location: admin.php”); is suppose to do that?

Now, when I click logout (As if I manually type admin.php in the url bar it works as if I am logged in), the header() function works and redirects me to the index page

[php]<?php

session_start();
$_session[‘name’] = ‘’;
session_destroy();
header(“Location: index.php”);

?>[/php]
That’s the logout code.

Hope that all makes sense as to what my problem is and I hope I have posted in the right part.

You need to re-arrange your html code somehow, so that there are no any output before header() function call. For example like this:
[php]<?php
mysql_connect(“localhost”,“root”,"");
mysql_select_db(“blog”);

$content=’’;

if(isset($_POST[‘submit’]))
{
$name = $_POST[‘name’];
$password = $_POST[‘password’];
$result = mysql_query(“SELECT * FROM members WHERE name=’$name’ AND pass=’$password’”);
$num = mysql_num_rows($result);
if($num == 0){
$content=“User name and password do not match. Please try again”;
}
else
{
session_start();
$_SESSION[‘name’] = $name;
header(“Location: admin.php”);
exit;
}
}
else
{
$content=’
Username:

Password:


';
}
?>

Login <?php echo $content ?> [/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service