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 trialkarthikkn
5,397 PointsHow 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
shiv sandhu
Full Stack JavaScript Techdegree Student 9,979 PointsAre you using Database for storing the user information?
If yes, Then you can use mysqli (For mysql Database) or PDO.
For example -
when user clicks submit button you can send user information to page like process.php (With post method).
In process.php you can check if the user information is valid or not.
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.
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).
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.
karthikkn
5,397 Pointshi, shiv sandhu
can you explain the above process with the help of code
shiv sandhu
Full Stack JavaScript Techdegree Student 9,979 PointsAre you using database for storing using information?
karthikkn
5,397 Pointsyes
Thanks for help again shiv