How to upload different profiles on the same page?

0

I have a site (or I'm doing it) where I can see the profile of the user that I select from index.html .

This page where the user's data is loaded is called user.php and the page where I see the profile of the current user (logged in) is called profile.php .

That idea was given to me long ago that there must be two pages, the ones mentioned above.

Well, I was watching the operation of this site, the twitter, facebook, etc and I realized that the only thing that changes is the id or username when I move from one to another.

I'll explain:

When you visit your profile on facebook in the url you have:

https://www.facebook.com/profile.php?id=100010542947857(este es el mio),

By the simple fact of changing a number of that, it takes me to another profile, but it's still the same page, that is, profile.php . And what is it that changes? the design changes, the only thing that changes are the buttons, in the profile of the logged-in user they leave you, update information, see the activity log, and if you go to another profile you will get the message buttons, send request, etc.

for example:

http://es.stackoverflow.com/users/12878/luis

ese es la dirección de mi perfil.

but if there is a user named jose2000 and I want to go to his profile I just have to delete "luis" (from the end of the address above) and put "jose2000".

So my question is, can not do that with a single page, for example "profile.php" and when I enter the profile of the logged in user not only uploads their data but also the configuration buttons, modify profile , etc.

I do not know if they understand.

    
asked by luis 26.11.2016 в 04:46
source

2 answers

1

You can do it without problems with a single page, the only thing you need is to verify that the identified user is the same as the one that is showing in profile.php.

Since you have not shown any code, I can not give you an appropriate answer for your case, but I'll tell you how you could do it.

Suppose that on your page you have the user object to store the current session data, and that the profile page has the id parameter (like the example you have put on Facebook).

The only thing you need, is a conditional that includes the buttons, links or personal content only for the logged in user, you do it this way:

<?php if ($usuario && ($usuario->getId() == $_GET['id'])) { ?>
    ... Botones, enlaces o contenido a mostrar cuando se trata de tu propio perfil ...
<?php }?>

You should adapt the conditional to your user system but I think the idea is clear.

    
answered by 26.11.2016 / 18:29
source
1

Well if it's about rewriting the view in terms of MVC, now about editing users there are two cases:

  • Edit the data of any user you visit as a mode administrator
  • Only the authenticated user can modify their data.
  • As you will see it is necessary to manage roles per user, so what an administrator can do is restricted to a lower level user

    Here is a basic example of how to implement it, remember that the user identifier is the one you will use to load the data, you must extract data and load it in your view (user.php) through POST OR GET,

    link

    Lets go!

        
    answered by 26.11.2016 в 06:41