我正在创建一个个人资料页面,其中包括个人资料图片、用户名、标题和个人资料所有者的朋友列表。
我使用.htaccess 来允许用户在 URL 中写入,只是其他用户的名称而不输入? 访问个人资料页面。
但问题是,如果我在 URL 中写入名称,它可以工作,但是如果我输入 profile .php 或按 profile,它会显示基本页面,这意味着没有任何与此配置文件所有者相关的信息,比如新页面
如何解决这个问题?
配置文件.php
session_start();
require_once('include/connect.php');
$login = ($_SESSION['login']);
$userid = ($_SESSION['user_id']);
$login_user = ($_SESSION['username']);
$fname = ($_SESSION['first_name']);
$lname = ($_SESSION['last_name']);
ob_start();
$username = "";
$interactionBox = "";
if(isset($_GET['u'])) {
$username = mysql_real_escape_string($_GET['u']);
if(ctype_alnum($username)) {
//check ser exists
$check = mysql_query("SELECT user_name, first_name FROM user WHERE user_name = '$username'");
if(mysql_num_rows($check) == 1) {
$get = mysql_fetch_assoc($check);
$username = $get['user_name'];
$fname = $get['first_name'];
var_dump($username);
var_dump($login_user);
} else {
echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/lam-el-chamel/index.php\">";
exit();
}
}
}
?>
<?php
//check if the logued in user is diffrenet from the url username
if($username != $login_user) {
$interactionBox='<div class = "InteractionLinksDiv">
<a href= "#" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'add_friend\');">Add as Friend</a>
</div>';
} else { //check if the logued in user is equal to the url username
$interactionBox='<div style="display:inline; border:#CCC 1px solid; padding:5px; background-color:#E4E4E4; color:#999; font-size:14px;">
Others Can Add You.
</div>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Lam_El_Chamel</title>
<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css' />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
<!--[if IE 6]>
<link href="default_ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</script>
<script language="javascript" type="text/javascript">
//jquery function for toggeling member interaction container
function toggleInteractContainers(x) {
if($('#'+x).is(":hidden")){
$('#'+x).slideDown(200);
} else {
$('#'+x).hide();
}
}
//function to add friend recive 2 arguments
function addAsFriend(a,b) {
//alert("Member with id:" + a + "request friendship with the memeber with id:" + b);
var url = "script_for_profile/request_as_friend.php";
$("#add_friend").text("please wait...").show();
$.post(url,{request:"requestFreindship",mem1:a,mem2:b},function(data){
$("#add_friend").html(data).show().fadeOut(12000);
});
}
</script>
</head>
<body>
<?php require_once('header.php');?>
<div id="wrapper">
<div id="page-wrapper">
<div id="page">
<div id="wide-content">
<?php
$check_pic = mysql_query("SELECT profile_pic FROM user WHERE user_name= '$username'")or die(mysql_error());
$get_pic_row = mysql_fetch_assoc($check_pic);
$profile_pic_db = $get_pic_row['profile_pic'];
if($profile_pic_db == "") {
$profile_pic = "images/default_img.jpg".$profile_pic_db;
}
else {
$profile_pic = "userdata/profile_pics/".$profile_pic_db;
}
?>
<img src="<?php echo $profile_pic; ?>" height="150" width="196" alt="<?php echo $username; ?>'s profile" title="<?php echo $username; ?>'s profile" />
<br />
<div class="textHeader"><?php echo $username; ?></div>
<?php echo $interactionBox; ?>
<div class="interactContainers" id="add_friend">
<div align="right"><a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers('add_friend');">Cancel</a></div>
Add <?php echo $username ?> as Friend?
<a href ="#" onclick="return false" onmousedown="javascript:addAsFriend(<?php echo $_SESSION['user_id']; ?>,<?php echo $userid; ?>);">Yes</a>
</div>
<div class="interactContainers" id="friend_requests" style="background-color:#FFF ; height:240px; overflow:auto;">
<h3>The Following People want to be friends</h3>
</div>
<div class="profileLeftSideContent">Introduce YourSelf....<br />
<?php
$about_query = mysql_query("SELECT interest FROM user WHERE user_name = '$username'")or die(mysql_error());
$get_result = mysql_fetch_assoc($about_query);
$about_the_user = $get_result['interest'];
echo $about_the_user;
?>
.htaccess
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1 [L]