<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "abc", " ");
// Selecting Database
$db = mysql_select_db("run", $connection);
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User
$ses_sql=mysql_query("select username from user where username='$user_check'", $connection );
$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['username'];
if(!isset($login_session)){
mysql_close($connection); // Closing Connection
header('Location: index.php'); // Redirecting To Home Page
}
?>
我想在这里添加另一个会话名称是tele_id。但是当我试图对它进行广告时,它每次都会重定向失败。该怎么办。我可以在这里做广告,还是可以在这里使用两个会话???
答案 0 :(得分:1)
<?php
$user=$_POST["user"];//username from html form
$pwd=$_POST["pwd"];//password from html form
// Connect to the database
$con = mysql_connect("localhost","root","");
// Make sure we connected succesfully
if(! $con)
{
die('Connection Failed'.mysql_error());
}
// Select the database to use
mysql_select_db("db_name",$con);
$result = mysql_query("SELECT user_name, password FROM admin where user_name='$user'"); //Query to retrive data from database and check with entered data
$result1 =mysql_query("select tele_id from user where username='$user_check'", $connection ); //Query to retrive data from database and check with entered data
$row = mysql_fetch_array($result);
$row1 = mysql_fetch_array($result1);
$tele_id=row1["tele_id"];
if($row["user_name"]==$user && $row["password"]==$pwd)
{
echo"You are a validated user.";
session_start();
$_SESSION['login_user'] = $user;
$_SESSION['tele_id'] = $tele_id;
header( "Location: AdminHome.php" );
}
else
echo "<script language=\"JavaScript\">\n";
echo "alert('Username or Password was incorrect!');\n";
echo "window.location='AdminLogin.php'";
echo "</script>";
?>
答案 1 :(得分:0)
$ _SESSION超级全局可以是用户作为数组。要在其中存储多个变量,请使用:
$_SESSION['login_user'] = your_value;
$_SESSION['tele_id'] = your_value;