farril Posted November 6, 2008 Share Posted November 6, 2008 hi there. im new to this forum, iv just started trying to learning php and get my head around it. ive got a website, with a simple login script (atm all it does is acknowledge you are logged in and display your username) ive got a login form, but when you login i want that login form to disapear and have another form containing your user control panel. im having real trouble doing this. how do i go about adding this feature? Link to comment https://forums.phpfreaks.com/topic/131641-php-if-statements-with-forms/ Share on other sites More sharing options...
rhodesa Posted November 6, 2008 Share Posted November 6, 2008 Have you started using SESSIONS yet? They are used to store data between pages. So if you store something in a session, it will be available on the next page, etc. Once you have validated their login, you will want to store something in the SESSION. For this example, let's user $_SESSION['user']: $_SESSION['user'] = $user; Now, you should redirect them to whatever page you need to. Finally, on that page, the code would look like: if($_SESSION['user']){ //Logged In //print User Control Panel }else{ //Not Logged In //print Login Form } Note: In every script that uses sessions, make sure you put the following function at the very beginning of the script: session_start(); Link to comment https://forums.phpfreaks.com/topic/131641-php-if-statements-with-forms/#findComment-683744 Share on other sites More sharing options...
mrMarcus Posted November 6, 2008 Share Posted November 6, 2008 it'd be something like... <? if(isset($_SESSION['auth'])){ //display links, etc. for people who are logged in... }else{ //display login form or whatever it is you want people to see who aren't logged in... } i mean, that's it in it's simplest form assuming you are using $_SESSION variables to keep track of the login process. i have nothing else to work with in the way of any of your code .. but that's the general idea. Link to comment https://forums.phpfreaks.com/topic/131641-php-if-statements-with-forms/#findComment-683745 Share on other sites More sharing options...
farril Posted November 6, 2008 Author Share Posted November 6, 2008 thanks guys. all fixed now. its the <?php if(logged in){ ?> FORM HERE <?php } ?> that i didnt get i had to do. but after searching abit more on this forum i found out how to do it. Link to comment https://forums.phpfreaks.com/topic/131641-php-if-statements-with-forms/#findComment-683765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.