What is the best way to create member profiles in PHP? For instance, some websites read in the address bar: profile.php?id=11233 and then profile.php?id=13563. How is this actually done? As of now, I am saving such types of URL’s in MySQL, but where will I write the actual code? Will I have to write the code in profile.php? Or will I have to make separate files for each id? How does it work?
Share
Yes. Visitors will be visiting
profile.phpand there will be a default variable set named$_GET['id']that has the value in the URL, like11233or13563. You can then query the database for the user with that id and display the proper information.If there is more than one variable, like
profile.php?id=123&type=cake, then you will have two variables:$_GET['id'] = 123, $_GET['type'] = 'cake'. It is stored in$_GETbecause GET is the method used to access the page. Find out more at http://php.net/getThere is also another common method, called
POST. This is used when forms are submitted withmethod=POST. In that case, the information will be stored in the$_POSTarray.