1

我已经完成了以前的尝试来解决这个问题,但似乎无法解决这个问题。我得到的是一个用户页面 user.php,其中包含类似 user.php?u=Chris

我正在尝试将其重写如下

RewriteEngine On
RewriteRule ^user/([a-zA-Z0-9]+)/$ user.php?u=$1 [NC]

使其显示为 www.mydomain.com/user/chris

每次我尝试访问该页面时,我都会遇到我自己的消息未记录......来自下一节中的 msg=notlogged。我认为这是重写后 get 变量的问题。这有什么道理吗,还是我看错了?如何维护 get 变量以便可以在我的数据库中检查你?

<?php
include_once("../includes/check_login_status.php");
// Initialize any variables that the page might echo
$u = "";
$userlevel = "";
$profile_pic = "";
$profile_pic_btn = "";
$avatar_form = "";
$joindate = "";
$lastsession = "";
// Make sure the _GET username is set, and sanitize it
if(isset($_GET["u"])){
$u = preg_replace('#[^a-z0-9]#i', '', $_GET['u']);
} else {
   header("location: http://www..com");
    exit(); 
}

// Select the member from the users table
$sql = "SELECT * FROM transactions WHERE username='$u' AND activated='1' LIMIT 1";
$user_query = mysqli_query($db_conx, $sql);
// Now make sure that user exists in the table
$numrows = mysqli_num_rows($user_query);
if($numrows < 0){
header("location: http://www..com/message.php?msg=notlogged");
    exit(); 
}
// Check to see if the viewer is the account owner
$isOwner = "no";
if($u == $log_username && $user_ok == true){
$isOwner = "yes";
$profile_pic_btn = '<a href="#" onclick="return false;" onmousedown="toggleElement(\'avatar_form\')">Toggle Avatar Form</a>';
$avatar_form  = '<form id="avatar_form" enctype="multipart/form-data" method="post" action="php_parsers/photo_system.php">';
$avatar_form .=   '<h4>Change your avatar</h4>';
$avatar_form .=   '<input type="file" name="avatar" required>';
$avatar_form .=   '<p><input type="submit" value="Upload"></p>';
$avatar_form .= '</form>';
}
else 
var_dump($_GET);
//header("location: http://www..com/message.php?msg=notlogged");
// Fetch the user row from the query above
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$profile_id = $row["id"];
$userlevel = $row["userlevel"];
$avatar = $row["avatar"];
$signup = $row["signup"];
$email = $row["email"];
$username = $row["username"];
$lastlogin = $row["lastlogin"];
$joindate = strftime("%b %d, %Y", strtotime($signup));
$lastsession = strftime("%b %d, %Y", strtotime($lastlogin));
}
$profile_pic = '<img src="user/'.$u.'/'.$avatar.'" alt="'.$u.'">';
if($avatar == NULL){
$user1 = "";
$profile_pic = '<img src="images/avatardefault.jpg" alt="'.$user1.'">';
$username ="'.$email.'";
}
?>
<?php 
$coverpic = "";
$sql = "SELECT filename FROM photos WHERE user='$u' ORDER BY RAND() LIMIT 1";
$query = mysqli_query($db_conx, $sql);
if(mysqli_num_rows($query) > 0){
$row = mysqli_fetch_row($query);
$filename = $row[0];
$coverpic = '<img src="user/'.$u.'/'.$filename.'" height="200" width="200" alt="pic">';
}
?>

<?php
// If the page requestor is not logged in, usher them away
$notification_list = "";
$sql = "SELECT * FROM notifications WHERE username LIKE BINARY '$log_username' ORDER BY date_time DESC";
$query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($query);
if($numrows < 1){
$notification_list = "You do not have any notifications or you're viewing a fellow traders profile";
} else {
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$noteid = $row["id"];
$initiator = $row["initiator"];
$app = $row["app"];
$note = $row["note"];
$date_time = $row["date_time"];
$date_time = strftime("%b %d, %Y", strtotime($date_time));
$notification_list .= "<p><a href='user.php?u=$initiator'>$initiator</a> | $app<br />$note</p>";
}
}
mysqli_query($db_conx, "UPDATE transactions SET notescheck=now() WHERE username='$log_username' LIMIT 1");
?>

这就是我的 htaccess 重写中的全部内容。我有这个迈克尔。

RewriteEngine On
        RewriteCond %{SERVER_PORT} 80
        RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^/?$ "http\:\/\/www\.mydomain\.com\/" [R=301,L]

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^user/([a-zA-Z0-9]+)/$ user.php?u=$1 [NC]
4

0 回答 0