Answer the question
In order to leave comments, you need to log in
How to make User Profile ReWrite instead of index?
Hello.
Database structure:
id, login, nickname
1, [email protected], pipiska
There is a profile.php file where I can edit this data.
Goal:
Make it so that user profiles can be opened by a URL like this: site.ru/pipiska
Where pipiska = nickname from our database.
How to implement this and in which file to receive any data?
$id = 0;
if($_GET['id'])
{
$user = R::findOne('users', 'id = ?', array($_GET['id']));
if($user)
$id = $_GET['id'];
}
if(isset($_SESSION["logged_user"]))
{
if($id)
{
$profile = user($id);
echo '$profile["nickname"]';
}else{
echo 'пользователь не найден';
}
}else{
echo '1111';
}
function user($id)
{
if(!$id)
{
$id = $_SESSION['logged_user']->id;
if(!$id)
return false;
}
$user = R::findOne('users', 'id = ?', array($id));
if($user)
{
$data["id"] = $user->id;
$data["login"] = $user->login ? $user->login : "login";
$data["nickname"] = $user->nickname ? $user->nickname : "nickname";
return $data;
}
return false;
}
RewriteRule ^profile/([0-9]+)/? profile.php?id=$1 [L]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question