duanmu8911 2013-12-28 18:23
浏览 37
已采纳

Login.php没有重定向

On this login page when I try to login it gives a blank page. Though login is successful as on clicking the profile tab the dashboard.php is visible. Also this whole thing works just fine in my WAMP server.

What is causing this issue?

<?php

ob_start();
$host="localhost"; // Host name 
$username="######"; // Mysql username 
$password="######"; // Mysql password 
$db_name="devspan_Users"; // Database name 
$tbl_name="Members"; // Table name 

// Connect to server and select databse.
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_query("CREATE DATABASE IF NOT EXISTS ".$db_name);
mysql_select_db("$db_name",$con)or die("cannot select DB"); 



if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$tbl_name."'",$con))==0)
{
$sql="CREATE TABLE Members(
id int(4) NOT NULL auto_increment,
username varchar(65) NOT NULL default '',
password varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
)";
mysql_query($sql,$con);
}

// Define $myusername and $mypassword 
$myusername=$_POST['username']; 
$mypassword=$_POST['password']; 

// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql,$con);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword
if($count==1){
// Register 
session_start();
$_SESSION["myusername"]=$myusername;
$_SESSION["mypassword"]=$mypassword; 
header("location:dashboard.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
  • 写回答

2条回答 默认 最新

  • doubijiao2094 2014-01-01 08:02
    关注

    Update: The Problem was with my hosting not my code. sql queries took a lifetime to fetch data, hence the page did not load. Solution: Changed my Hosting service.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?