K
K
kickass772021-06-29 18:07:17
PHP
kickass77, 2021-06-29 18:07:17

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;
  }


Here is a raw version, but I can display it like profile?id=1
But I don’t understand how to display the corresponding nickname = pipiska at the URL: site.ru/pipiska
And display the same nickname there, or the login of the corresponding user...

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 question

Ask a Question

731 491 924 answers to any question