my sessions.php
<?php
include('config.php');
session_start();
$user_check = $_SESSION['login_user'];
$ses_sql = mysqli_query($db,"select username from admin where username = '$user_check' ");
$row = mysqli_fetch_array($ses_sql, MYSQLI_ASSOC);
$login_session = $row['username'];
if(!isset($_SESSION['login_user'])){
header("location:login.php");
}
虽然我得到了一个error的登录页面,只要传递了正确的参数1
my welcome.php
<?php
include('sessions.php');
?>
<html>
<head>
<title>Welcome </title>
</head>
<body>
<h1>Welcome <?php echo $login_session; ?></h1>
<h2><a href = "logout.php">Sign Out</a></h2>
</body>
</html>
答案 0 :(得分:0)
您的上一个查询似乎未正确执行。
从我看到的情况来看,它似乎无法找到您的sessions.php文件,因此无法识别$ _SESSION [&#39; login_user&#39;]。
您可以使用一些调试并使用var_dump()和mysqli_error()
等功能var_dump($_SESSION['login_user']); // Check your result. It's probably coming as NULL.
$ses_sql = mysqli_query($db,"SELECT username FROM admin WHERE username = '".$user_check."' ") or die(mysqli_error($db));
if ($ses_sql) {
$row = mysqli_fetch_array($ses_sql, MYSQLI_ASSOC);
echo '<pre>';
print_r($row);
}
答案 1 :(得分:0)
主要问题在于您的session.php
页面。您的$_SESSION['login_user']
没有任何价值,这就是为什么query
不是executing
而其他任何内容都无效的原因。
我们必须始终确保我们正在使用的variables
具有一定的价值,然后我们应该使用它们,并使用mysqli_error()
functions
来检查error
是否有session.php
<?php
include('config.php');
session_start();
//echo $_SESSION['login_user'];die
if(isset($_SESSION['login_user'])){
$user_check = $_SESSION['login_user'];
$ses_sql = mysqli_query($db,"select username from admin where username = '$user_check' ") or die(mysqli_error($db));
$row = mysqli_fetch_array($ses_sql, MYSQLI_ASSOC);
$login_session = $row['username'];
}
else
{
header("location:login.php");
}
。
所以用这个
更改你的代码sql injection
*使用 PDO 保护您的代码免受public class BlankFragment extends Fragment {
private ImageView imv1;
private ImageView imv2;
private ImageView imv3;
private ImageView imv4;
private ImageView imv5;
private ImageView imv6;
private ImageView imv7;
private ImageView imv8;
private ImageView imv9;
ProgressDialog progressDialog = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_blank, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
imv1 = (ImageView) getActivity().findViewById(R.id.imageView);
imv2 = (ImageView) getActivity().findViewById(R.id.imageView2);
imv3 = (ImageView) getActivity().findViewById(R.id.imageView3);
imv4 = (ImageView) getActivity().findViewById(R.id.imageView4);
imv5 = (ImageView) getActivity().findViewById(R.id.imageView5);
imv6 = (ImageView) getActivity().findViewById(R.id.imageView6);
imv7 = (ImageView) getActivity().findViewById(R.id.imageView7);
imv8 = (ImageView) getActivity().findViewById(R.id.imageView8);
imv9 = (ImageView) getActivity().findViewById(R.id.imageView9);
}
private void setImage() {
// show progress dialog
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// set your images here.
}
});
// dismiss progressDialog here
}
}