这是我的 drop.php -6ren">
gpt4 book ai didi

php - 当我登录时如何将我的 id 值传递给其他 php 文件

转载 作者:行者123 更新时间:2023-11-29 13:20:58 25 4
gpt4 key购买 nike

这是我的 checklogin.php

<?php
session_start();
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="password"; // Mysql password
$db_name="lecturer"; // Database name
$tbl_name="members"; // Table name

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

// Define $myusername and $mypassword

$myid=$_POST['myid'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myid = stripslashes($myid);
$mypassword = stripslashes($mypassword);
$myid = mysql_real_escape_string($myid);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE ID='$myid' and password='$mypassword' LIMIT 1 ";
$result=mysql_query($sql);

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

// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
$_session['myid'] = 'myid';
$_session['mypassword'] = 'mypassword';
$info = mysql_fetch_array($result);
if($info['id'] == 0){
header("location: webpage.php");
}
else if ($info['id'] == 100) {
header("location: lecturer_user.php?myid=$myid");
}
else if ($info['id'] == 102) {
header("location: lecturer_user.php");
}
else {
echo "Wrong Username or Password";
header ("refresh:5; url=main_login.php");

}
}
ob_end_flush();
?>

<html>
<body>
<table>
<th><a href="main_login.php?pressed=back">Back</a></th>
</table>
</body>
</html>

这是我的讲师_user.php

<?php
session_start();
echo "<a href=\"drop.php?myid=".$_SESSION['myid']."\">drop</a>";
?>

这是我的 drop.php

<html>
<head></head>
<body>

<?php

$conn = mysql_connect('localhost','root','password');
mysql_select_db('lecturer');



$myid = $_GET["myid"];

$query = 'SELECT persons.ID , persons.FirstName , user_subject.subject
FROM persons
INNER JOIN user_subject
ON persons.ID = user_subject.ID
WHERE persons.ID = '.$myid.' ORDER BY user_subject.subject';

$result = mysql_query($query) or die(mysql_error());
?>


<table width="400" border="0" align="center" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Drop subject</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Subject</strong></td>

</tr>

<?php while($row = mysql_fetch_assoc($result)) { ?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="data[]" value="<?php echo $row['ID'];?>" /></td>
<td bgcolor="#FFFFFF"> <?php echo $row['ID']; ?> </td>
<td bgcolor="#FFFFFF"> <?php echo $row['subject']; ?> </td>

</tr>
<?php } ?>
<tr>
<td colspan="3" align="left" bgcolor="#FFFFFF"><input type="submit" value="Delete Checked Rows" /></td>
<td colspan="2" align="right" bgcolor="#FFFFFF"><a href="user_subject.php?pressed=subject">Back</a></td>


</tr>


<?php
if(isset($_POST['data'])) {
$del_query = "DELETE FROM user_subject WHERE ID IN (";
foreach($_POST['data'] as $data) {
$del_query .= "'" . (int) $data . "',";
}
$del_query .= "'')";
mysql_query($del_query) or die(mysql_error());
header("Location:" . $_SERVER['PHP_SELF']);
}



mysql_close()


?>
</table>
</form>
</tr>
</table>
</body>
</html>

我想做的是,当我以 id = 100 身份登录时,它将导致讲师_user.php?myid=100主要问题是当我在讲师用户中时,我希望 session ID 识别为 id=100,这样每个用户都有自己的唯一 ID当我点击testing.php的 View 时,它会将其重定向到testing.php?myid=100,这样我只能查看id = 100的主题,而不能查看其他主题。

我想要的是当用户 ID 100 登录时只能查看自己的个人资料。谢谢

谢谢

最佳答案

您正在设置

 $_session['myid'] = 'myid';

使用

 $_session['myid'] = $info['id'];

在 checklogin.php 中

关于php - 当我登录时如何将我的 id 值传递给其他 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20852868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com