0

I made login and registration system. It works fine but the main problem is user profile page. I made a profile.php page but it works for each session. I need to make like this:

domain.com/profile/username

I mean when i click someone's username, i want it navigate me to the username's profile page. Bytheway i couldn't make $id = $_GET['username'] i can't get how it works. I'm working with $_POST to login.

How can i make profile page for each user?

Thank you.

Plunch
  • 43
  • 1
  • 8
  • Change the profile code to pull the username from the GET request and not the SESSION. Avoid `int` and use username for lookup. (presuming you make sure not to allow duplicate usernames). – Lawrence Cherone Dec 10 '17 at 22:23
  • Okay i'll try to use GET request to display user. Thanks Lawrence. – Plunch Dec 10 '17 at 22:27
  • Usernames are unique. I worked on it :) – Plunch Dec 10 '17 at 22:31
  • If you want `example.com/profile/username` and not `example.com/profile?id=username` you need to use rewrites. - [mod_rewrite, URL rewriting and “pretty links” explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Lawrence Cherone Dec 10 '17 at 22:33
  • I exactly want to do that. Rewrite is the key :) – Plunch Dec 10 '17 at 22:36

1 Answers1

0

In profile.php make a function that gets the URI example: Profile?id=1

$user = $_GET[‘id']; //make the database statement which gets all the info about $user and return this on the page

  • Everytime you enter /profile.php?id= the id you want it gets the user its profile picture or whatever you like – maurice bruijn Dec 10 '17 at 22:26
  • I'll brb when i try this. Thank you for the response. – Plunch Dec 10 '17 at 22:28
  • Is it possible to make profile/username with Get method ? – Plunch Dec 10 '17 at 22:29
  • No because the GET is meant to GET a value that has been set in the URI example of what you can do: profile/username?username= the user name WHICH means that you now can GET the username – maurice bruijn Dec 10 '17 at 22:30
  • I think that i want to use " / " instead of " ? " in the url. Because it seems easier to type for the users :) – Plunch Dec 10 '17 at 22:33
  • That is possible just hide the php ?username in your .htaccess BUT this doesnt mean that you get rid of the ? In your php you will need to use this but the user wont see it because the htaccess takes care of this – maurice bruijn Dec 10 '17 at 22:36