I need help here - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21) +---- Thread: I need help here (/showthread.php?tid=4090) |
I need help here - tartou2 - 12-31-2009 Hello SF I was creating my first website using php and i was doing great gathering the codes from here SF and from different tut around the internet. I have created the database and the tables, the register page and the login page and everything is fine for now. But after that i can't find how to show someone my username after i have logged in. for example i need to see my username somewhere in the index.php page and i really appreciate if anybody can help me with the code. Here are the codes: login.php PHP Code: <?php login.details.php PHP Code: <?php Anybody can help me with the code please thanks RE: I need help here - Grizzly - 12-31-2009 Have you tried echo or print? RE: I need help here - MattR - 12-31-2009 Surely you'd want to add slashes not strip them out...?? And what if someone puts a \ in their password?? You'll strip it out and break it. RE: I need help here - tartou2 - 12-31-2009 (12-31-2009, 09:55 AM)Grizzly Wrote: Have you tried echo or print? yes i tried the echo but it is not working. Nothing is shown on the index.php I think that i should use some syntaxes related to session , i saw that in few examples on the internet but i don't know how to implement them. But if there is another way, it would be better (12-31-2009, 11:15 AM)MattR Wrote: Surely you'd want to add slashes not strip them out...?? And what if someone puts a \ in their password?? You'll strip it out and break it. hmm i didn't test it with slaches. I will do some tests with other caracters to see how i can improve it. But so far no one give me the solution for the 1st problem RE: I need help here - tartou2 - 01-01-2010 No one can help me here? I have wrote this code in the index.php PHP Code: <?php and i can see "1" as a result on the index.php. This mean that i am logged in the website but i can't figure out how to bring the informations such as the username to index.php page. Anybody can help me with this? RE: I need help here - Gaijin - 01-01-2010 Want a Cookie? First you should have 2 variables for, mysql_query and mysql_num_rows. PHP Code: $query = mysql_query("select * from Users where Username='$loginusername' and Password='$loginpassword'"); Now when you execute the IF block, on the log-in success you should create a cookie along with the sessions. PHP Code: session_register("loginusername"); All you need to do next, is to read the cookie if it exists. PHP Code: if(isset($_COOKIE['UserName'])) { Your login.details.php would look like this now. PHP Code: <?php And anywhere in the index.php you place this. PHP Code: if(isset($_COOKIE['UserName'])) { EDIT: Also session_register is deprecated function since 5.3.0 and removed in PHP 6 Take a look here for more information! RE: I need help here - tartou2 - 01-01-2010 i have figured that by myself like an hour ago but i am facing troubles when removing the cookies. The fonction isn't working. PHP Code: $expirecookie=time()-3600; what i am doing wrong? And the server i am hosting my website still works with php v5 EDIT: Don't worry i don't have to remove the cookies thank for your help. At least you are the only one that gave the right solution |