Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

How to get the id of user in URL who logged in

Hi, I have created a login form, My question is When User logged in . i need to get his id in the URL

Reply me ASAP Thanks for help in advance

3 Answers

Are you using Database for storing the user information?

If yes, Then you can use mysqli (For mysql Database) or PDO.

For example -

  1. when user clicks submit button you can send user information to page like process.php (With post method).

  2. In process.php you can check if the user information is valid or not.

  3. If the information is valid you can store its ID (You can check user information with sql Statement using mysqli or PDO and get the user id ) in variable like $id = $_POST['id'] and redirect user to https://www.example.com/user/?id=$id.

  4. if the information is not valid then you can redirect user back to home page or echo out error message (You have to use if ... else statement in step 3 and 4).

  5. At last you can use $_GET['id'] to get the id from the link.

NOTE: You can use current page (Where user submit the form.) or any other page instead of process.php

If you not using Database or trying to ask something else then please let me know as your question is not clear.

hi, shiv sandhu

can you explain the above process with the help of code

Are you using database for storing using information?

yes

Thanks for help again shiv