我正在从我的 first.php 发送会话值并尝试从我的 second.php 获取。我已经对此进行了一些阅读,并且在我的本地主机上运行良好,但在我的服务器上根本无法运行。
这是我的 first.php 文件中的代码:
<?php
session_start();
ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="http://localhost/Shopping_biblioteka/css/style.css">
<title></title>
</head>
<body align="center">
<div id="login">
<?php
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
mysql_connect("localhost", "shopping_katalog", "logik@112233") or die(mysql_error());
mysql_select_db("shopping_katalog") or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
$result = mysql_query("SELECT password,id FROM x9qg6_users
where username='" . $username . "'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
$userhash = md5($password . $test[1]);
if ($test[0] === $userhash) {
$_SESSION['login_user'] = $user_id;
$_SESSION['username'] = $username;
$url = "biblioteka.php";
header("Location: $url");
}
} else {
echo 'Внесете ги вашите податоци во полињата!';
}
?>
<form action="" method="POST" accept-charset="UTF-8">
Корисничко име:<br/>
<input name="username" id="username" type="text"/><br/>
Лозинка:<br/>
<input type="password" id="password" name="password"/><br/>
<input type="submit" value="Логирај се!"/>
</form>
</div>
</body>
</html>
这是我的 second.php 文件:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="http://localhost/Shopping_biblioteka/css/style.css">
<title>Библиотека на</title>
</head>
<body>
<div id="wrapper">
<?php
$user_ID = $_SESSION['login_user'];
$logged_user = $_SESSION['username'];
?>
<h1 align="center" id="b_welcome">Добредојде <?php echo $logged_user; ?> во твојата библиотека! </h1>
<h4 align="center" id="b_info">Во твојата библиотека ги имаш следниве книги</h4>
<div id="knigi">
<?php
/* OVA E QUERITO
*
SELECT *
FROM Knigi k, poracki p
WHERE k.knigaid = p.kniga
AND p.korisnikInt = $user_ID
*
*/
//-----------------------------------
if(isset($_SESSION['login_user'])){
mysql_connect("localhost", "user", "pass) or die(mysql_error());
mysql_select_db("shopping_katalog") or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
$result = mysql_query("SELECT * FROM Knigi k, poracki p
WHERE k.knigaid = p.kniga AND p.korisnikInt ='" . $user_ID . "'");
while ($row = mysql_fetch_array($result)) {
//knigaid,naslov,avtor,link_do_pdf,thumb_link,kategorija,cena,br_strani
echo '<div id="item">';
echo '<a href="http://' . $row['link_do_pdf'] . '"><h5 align="center" id="b_item_title">' . $row['naslov'] . '</h5></a>';
//echo '<a href="http://' . $row['link_do_pdf'] . '">' . $row['avtor'] . '</a>';
echo '<a href="http://' . $row['link_do_pdf'] . '"><img src="http://' . $row['thumb_link'] . '" id="b_item_slika" /></a>';
echo '</div>';
}
if (!$result) {
echo 'Проблем со добивање на податоците: ' . mysql_error();
exit;
}
}else{
$url = "/index.php";
header("Location: $url");
}
?>
</div><!--kraj na knigite-->
</div>
</body>
</html>