0

I am trying to figure out the best way/how to go about this -

I am relatively new to mysql and PHP and need to create user profile pages that display different values from a mysql database that have been uploaded for each user -

for example if I clicked on John's profile, the page would display John's name, age, any other values that I have stored on John in my mysql table. This is from the perspective of someone else logged in who wants to view John's page.

Since all my index.php files for my different web pages are all in their own folders (i.e. the about page, settings page, etc) I originally thought to simply have a user profile folder and index.php that just outputs the right information in accordance with the $user_id of the user that was clicked. That is the only way I can think to accomplish this.

My problem is that this would not allow for a person to access a user profile via URL (i.e. website.com/user1) and I am not sure my approach is the best/correct way to create user profile pages. I have explored this question and read up on URL rewriting but am still unclear -

What is the correct way to create separate user profile web pages and how does URL rewriting tie into the actual contents of the page's index file?

Is there a way to (this is poorly worded) store a separate index.php file for each user within their existing mysql column and just direct to this file when clicked?

1
  • to create these kinds of urls (website.com/user1) without writing index.php to all user profiles, php frameworks like laravel would be helpful. Commented May 25, 2016 at 6:03

2 Answers 2

0

Hard to answer without knowing how the structure of your application is looking.

But the most common way, and the most simple implementation would be to:

  • create a profile.php (profile-action in user-controller or whatever..)
  • add the user-id to the url, yourapplication/profile.php?userid=12
  • In your profile.php you simply fetch the data which belongs to the given userid (first validate the id etc...)
  • fill your html with the fetched data

So in short: create a view, fill in dynamic data depending on the userinput

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. How would you add the user id onto the end of the URL? Right now I'm just navigating to the profile page using <a href= "/profile"></a> as I'm calling a function from a class and having problems with <a href= "website.com">
What would you recommend for passing the user id of the user link clicked to my profile index.php? Unclear how to do this with a href
Well you need to fetch the id of the user before you can write the link. It's impossible to answer exactly without knowing this part of your application.
Would you look at my more recent question? Still trying to figure this out - stackoverflow.com/questions/37447010/…
0

I don't think what you want to do is related to URL rewriting. URL rewriting is simply writing facebook.com/user1 instead of facebook.com/user1/index.php (or whatsoever).

"My problem is that this would not allow for a person to access a user profile via URL" I believe this part is incorrect. Someone who logged in as, say, user1 can view the page www.website.com/user2 and see another person's profile.

Check out this website to get a better understanding for URL rewriting. Facebook uses it as you can access a person's profile from facebook.com/user5. On the other hand, one comment suggested you to use dynamic php such as /profile.php?id=5. It is your choice what to pick. But the first option does not prevent users to check out others' profile pages on the contrary to what -I believe- you assumed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.