你好堆栈溢出目前我有点卡在我的 user_profile/username_here 上。问题是你可以填写你想要的每个用户名,如果你把它放在'/'后面,它仍然会显示编造的用户名是在 URL 后面登录的吗?我也在使用 URL 重写。htaccess:
RewriteEngine on
RewriteBase /
RewriteRule ^profile/([a-zA-Z0-9-\._]+)(\/)? /profile.php?username=$1 [L,QSA]
这是我用于 user_profile.php 的代码:
<?php
require_once('db.php');
session_start();
if(!isset($_SESSION['id'])) {
header("location: access_denied.php");
} else {
$username = $_SESSION['username'];
$firstname = $_SESSION['firstname'];
$lastname = $_SESSION['lastname'];
$result3 = mysql_query("SELECT * FROM tab where username='$username' AND firstname='$firstname' AND lastname='$lastname'");
if($row3 = mysql_fetch_array($result3)) {
$username = $row3['username'];
$firstname = $row3['firstname'];
$lastname = $row3['lastname'];
}
?>
<html>
<body>
<table width="398" border="0" align ="center" cellpadding="0">
<tr>
<td height ="26" colspan="2">Profile info</td>
<td><div align="right"><a href="log_out.php">Logout</a></div></td>
</tr>
<tr>
<td width="129" rowspan="5"><img src="<?php echo $picture?>" width="129" height="129" alt="no image found"/></td>
<td width="82" valign="top"><div align="left">Username:</div></td>
<td width="165" valign="top"><?php echo $username ?></td>
</tr>
<tr>
<td width="82" valign="top"><div align="left">Firstname:</div></td>
<td width="165" valign="top"><?php echo $firstname ?></td>
</tr>
<tr>
<td width="82" valign="top"><div align="left">lastname:</div></td>
<td width="165" valign="top"><?php echo $lastname ?></td>
</tr>
</table>
<p align="center"><a href="index.php"></a></p>
</body>
</html>
<?php
}
?>
我需要将代码放在哪里,以便当前登录的用户名在 url 后面?欢迎解释,因为我对 PHP 还很陌生。另外,如果您看到任何错误,请说出来。