Вопрос

I am trying to build a small social network that will have a very simple functionality. No friend requests, no picture albums, no likes. All users have access to each others profiles but only the logged in user can modify the info on his/her page.

So far I managed to create the registration logic as well as the login check logic. By creating a session for user_id, I can retrieve user's info and populate the different areas of his/her profile page.

My problem has to do with the logic that needs to be applied in order for the logged in user to be able to view other user's profile page. I 've created a suggest search box that successfully shows a drop down list of other users results according to the data the logged in user has put into. Each result redirects to the profile.php layout and waits to be populated. I am guessing I have to apply more sessions but I reached to the point where I cannot see things clear and it would be useful if I could have your opinion on this matter.

Please bear in mind that I am only doing this project in order to improve my skills and secondly I only need the logic and this is the reason I have not posted any code. Thank you in advance!

Это было полезно?

Решение

You have to pass (for example) an id to the script.

profile.php?id=456

where 456 is the user id of the user you want to open the profile.

You can then do in the profile.php something like

$st = $db->prepare('SELECT * FROM profiles WHERE user_id = ?');
$st->execute(array($_GET['id']));

and receive the information to output.

The information in $_SESSION should only be used for the current user. Meaning if you have a script my_profile.php you do not need to pass an id, since you can get the current logged in user-id from $_SESSION.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top