user3475724
user3475724

Reputation:

How to show page of current user by id

I'v implemented user's page using PHP and MySQl improved, but at the moment the user is the only one, who can see his page(and only if logged in). How to implement, that other users can see his page. User has id, which is shown him in the url address like this :

  header("Location:http://website/page.php?id={$_SESSION['id']}"); 

How to make such system, when anyone opens http://website/page.php?id=1and this or that data and functionality is shown depending on whether it be the logged owner of the page or other user. I guess, that I should get id from url and work with it. How can I do this or how must be such basic things implemented?

Some additional php code (not sure, if it helps)

<?php
     session_start();
    include ("bd.php");
    if ( isset( $_SESSION['login'] ) ) {
       $login    = $_SESSION['login'];

      }

    else{

         exit("You are not logged in");
    }

?>

// html code

So, the general question is how to build a basic system of naming pages. For example, I go to website/page.php?id=3 and see page of user with id=3, and if I go to website/page.php?id=5 I will see page of user with id=5. How to get id from url?

Upvotes: 0

Views: 426

Answers (2)

D_R
D_R

Reputation: 4962

From what I've understand you want to create a profile page for users and to show specific data if the current user is viewing his own profile.

That's how you should approach this task:

  1. You need to have a User table in the database that will contain the user_id and other additional information as you need.

  2. Create a login page and save the user & password (encrypted and salted of course) in the session/cookie.

  3. when creating the profile check if the the current user is viewing this page with the user & password from the cookie/session you've just created.

Upvotes: 1

Dan
Dan

Reputation: 11084

I'm guessing there is code in your page that relies on $_SESSION['id'] to figure out which user page to show. Instead use $_GET['id'].

Upvotes: 2

Related Questions