I have already created profile pages, but they can only be seen by the person who is logged in. How can I make them public so that other people can view them?

Basically I want to make it so that if the user is logged in, they can edit their profile, and if they are not, they can view their profile (and other people's profile pages)

Member Avatar for diafol

Well it looks as though you've set up your system to protect profiles from users who have not logged in. All you need to do if something like this:

Get user ids and usernames from DB:

<a href="www.example.com/profile.php?id=231">ardav's profile</a>
<a href="www.example.com/profile.php?id=706">greenelf's profile</a>

The in your profile.php page:

if(isset($_GET['id'])){
    $edit = false;
    $id = intval($_POST['id']);
    if(isset($_SESSION['login_id']) && $id == $_SESSION['login_id']){
        $edit = true;
    }
    $result = ... (etc)
}

Now you can control the output based on the value of $edit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.