这是我用来确定是否让用户进入的 login.php 脚本。
<?php
if(isset($_POST['submitted']))
{
$errors= array();
$username = ($_POST['username']);
$pass = ($_POST['pass']);
$shapass = sha1($pass);
$_POST['username'] = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
if ($_POST['username'] == "") {
$errors[] = "Please enter your username.";
}
if ($_POST['pass'] == "") {
$errors[] = "Please enter your password.";
}
if(is_array($errors))
{
echo '<font color="red"><div align="center" class="error"><span></span><ul>';
while (list($key,$value) = each($errors))
{
echo '<li>'.$value.'</li><br />';
}echo'</ul></div></font>';
}
if(empty($errors))
{
$user_name = "root";
$password = "";
$database = "rsswebapp";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found)
{
$match = "Select ROWID,EMAIL,PWD from `user` ".
" where (USERNAME='$username' OR EMAIL='$username') and PWD='$shapass' ";
$qry = mysql_query($match);
/*
$uid = isset($_POST['username']) ? $_POST['username'] : $_SESSION['username'];
$pwd = isset($_POST['pass']) ? $_POST['pass'] : $_SESSION['pass'];
*/
$num_rows = mysql_num_rows($qry);
if ($num_rows <= 0) {
//unset($_SESSION['uid']);
//unset($_SESSION['pwd']);
header('location:index.php?msg=' . urlencode(base64_encode("Sorry, there is no username $username with the specified password.Try again!")));
}
else
{
session_start();
$_SESSION['ROWID'] = $sid ;
header("location:dashboard.php");
}
mysql_close($db_handle);
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}
}
}
?>
如果登录成功,我将用户重定向到 dashboard.php
<body>
<div class="container">
<div id="sidebar">
<ul>
<li><a href="dashboard.php?p=categories"><center>Categories</center></a></li>
<li><a href="dashboard.php?p=myfeeds"><center>My Feeds</center> </a></li>
<li><a href="dashboard.php?p=managefeeds"><center>Manage Feeds</center></a> </li>
<li><a href="dashboard.php?p=myfeed"><center>Account</center></a></li>
<li><a href="logout.php"><center>Log Out</center></a></li>
</ul>
</div>
<div class="main-content">
<div class="swipe-area"></div>
<a href="#" data-toggle=".container" id="sidebar-toggle">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</a>
<div class="content">
<?php
session_start();
$sid = $_SESSION['ROWID'];
if(!$_SESSION){
header('location:index.php?msg=' . urlencode(base64_encode("Please login to continue.")));
}
else
{
$pages_dir = 'pages';
if(!empty($_GET['p'])){
$pages = scandir($pages_dir,0);
unset($pages[0],$pages[1]);
$p = $_GET['p'];
if(in_array($p.'.php',$pages))
{
include($pages_dir.'/'.$p.'.php');
}
else
{
echo "Sorry, page not found.";
}
}
}
?>
<p></p>
</div>
</div>
</div>
</body>
问题出现在 myfeed.php 中:
<?php
$user_name = "root";
$password = "";
$database = "rsswebapp";
$server = "127.0.0.1";
//$db_handle = mysqli_connect($server, $user_name, $password,$database);
$db_handle = new mysqli($server, $user_name, $password,$database);
$db_found = mysqli_select_db( $db_handle,$database);
//session_start();
// $s = mysql_real_escape_string($_SESSION['ROWID']);
//$query = "SELECT URL,TITLE FROM rssfeeds,user WHERE rssfeeds.USERID=user.ROWID";
// $query = "select GROUP_CONCAT(r.URL) as URL from user as u Left Join rssFeeds as r On u.ROWID = r.USERID WHERE USERID = $_SESSION";
// $query = "SELECT URL FROM rssfeeds as rss WHERE rss.USERID=$s";
// $query = "SELECT `rssfeeds`.`URL` FROM `rssfeeds` WHERE `rssfeeds`.`USERID`=$_SESSION['ROWID']";
// $query = "SELECT URL FROM rssfeeds as rss ,user as userrss WHERE rss.USERID='$sid'";
//$query = "SELECT rssfeeds.URL FROM rssfeeds LEFT JOIN user ON rssfeeds.USERID=user.ROWID";
$query = "SELECT URL FROM rssfeeds as rss WHERE rss.USERID='" . $_SESSION["ROWID"] . "'";
//$query = "SELECT URL FROM rssfeeds as rss,user WHERE rss.USERID="$_SESSION['ROWID']"";
// $result = mysqli_query($db_handle,$query);
$result = mysqli_query($db_handle,$query);
// $result = $db_handle->query($query);
$r = array();
$index = 0;
if($result)
{
echo "BG </br>";
// while($row = mysqli_fetch_assoc($result)) {
while($row = $result->fetch_array()){
// while( ($row = mysql_fetch_assoc($result))!== false){
//echo "WELL DONE";
echo "{$row["TITLE"]} {$row["URL"]} </br>" ;
// $r[$index] = $row["URL"];
// $index++;
// printf ("%s \n", $row["URL"]);
}
echo "HX";
/*
$yourArray = array();
$index=0;
while($row = $result->fetch_array()){
echo "b";
// echo "<a href='".$row["URL"]."'>".$row["TITLE"]."</a>";
$yourArray[$index] = $row;
$index++;
echo "<br />";print_r($yourArray);
}
*/
}
else
{
echo "HELLO";
die(mysql_error());
}
?>
注释掉的语句是我尝试过但不起作用的语句。我无法从数据库表中检索 URL 并将它们显示在页面上。截至目前,我得到的输出为:
BG HX
我的数据库中有两个表:
- 用户
- RSS订阅
“用户”包含四列,即:
- ROWID(自动增量,主要)
- 用户名
- 电子邮件
- 残疾人士
而“rssfeeds”有四个:
- RSSFEEDID
- 用户身份
- 标题
- 网址
我很确定问题在于 $_SESSION 部分中 myfeed.php 中的查询。