Chrisj Posted September 22, 2014 Share Posted September 22, 2014 When I asked how to make this Log In Form disappear once it performs it's function: <form action="../login.php" method="post" accept-charset="UTF-8" class="middletext" onsubmit="javascript:this.style.display='none';"> <p> <input type="text" size="20" name="user_name_login" id="user_name_login" value="ENTER USERNAME" style="color:#D9D9D9" style="vertical-align:middle"; onfocus="if (this.value=='ENTER USERNAME') {this.value=''; this.style.color='#696969';}" > <input type="text" size="20" name="password_login" id="password_login" value="ENTER PASSWORD" style="color:#D9D9D9" style="vertical-align:middle"; onfocus="if (this.value=='ENTER PASSWORD') {this.value=''; this.style.color='#696969';}" > <input type="hidden" name="cookie_time" value="10080" /> <img src="../themes/default/images/arrow-red.png" alt="" /><input type="submit" style="outline:grey" font-size="5px" value="[var.lang_login_now]" class="button-form2" /> <input type="hidden" name="submitted" value="yes" /> <input type="hidden" name="remember_me" value="remember_me" /> </p> </form> </div> <!--Begin Sub-Navigation. This only appears when a user is logged in.--> <div class="container1"> <div class="menu1"> <div class="sub-nav"><a href="../index.php"></a> <img src="../themes/default/images/arrow-red.jpg" style="vertical-align:middle" alt="" /><a href="../members/[var.user_name]"> my account</a><img src="../themes/default/images/arrow- red.jpg" style="vertical-align:middle" alt="" /> <a href="../credits.php">[var.lang_my_credits]: [var.member_credits]</font></a><img src="../themes/default/images/arrow-red.jpg" style="vertical-align:middle"><a href="../logout.php">[var.login_out]</a> <!--[onload;block=div;when [var.loggedin]=1;comm]--> </div> I was given this line of code: if($_SESSION['loggedin'] == true){ //dont show form } else { //show form } But I don't know how/where to integrate it into the Form. Any help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/ Share on other sites More sharing options...
mac_gyver Posted September 22, 2014 Share Posted September 22, 2014 what is the context of this html/form? is it part of a template file that allows php code to be used in it or would you have to use the template's own conditional logic? what is the template engine? is it the only thing in a template file so that the entire template itself could be conditionally rendered by the main php code? Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491833 Share on other sites More sharing options...
ginerjm Posted September 22, 2014 Share Posted September 22, 2014 1 - you displayed a form 2 - the user typed in credentials 3 - the user 'submitted' the form to your validation script 4 - your script validates and ??? What do you want to do after the user is logged in? Send him to a 'start' screen? Send him to the screen he attempted to go to before he logged in? Whatever it is at step #4 is when you send something to the client again to give the user something to work on. If it's the method you need to use, you can do this: $url = 'somescriptname'; header("Location: $url"); // some browsers insist on this exact format exit(); Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491837 Share on other sites More sharing options...
QuickOldCar Posted September 22, 2014 Share Posted September 22, 2014 I switched it around a little, am pretty sure this is what you wanted. I added the first <div> to the form <?php if(!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] != true){ ?> <div> <form action="../login.php" method="post" accept-charset="UTF-8" class="middletext" onsubmit="javascript:this.style.display='none';"> <p> <input type="text" size="20" name="user_name_login" id="user_name_login" value="ENTER USERNAME" style="color:#D9D9D9" style="vertical-align:middle"; onfocus="if (this.value=='ENTER USERNAME') {this.value=''; this.style.color='#696969';}" > <input type="text" size="20" name="password_login" id="password_login" value="ENTER PASSWORD" style="color:#D9D9D9" style="vertical-align:middle"; onfocus="if (this.value=='ENTER PASSWORD') {this.value=''; this.style.color='#696969';}" > <input type="hidden" name="cookie_time" value="10080" /> <img src="../themes/default/images/arrow-red.png" alt="" /><input type="submit" style="outline:grey" font-size="5px" value="[var.lang_login_now]" class="button-form2" /> <input type="hidden" name="submitted" value="yes" /> <input type="hidden" name="remember_me" value="remember_me" /> </p> </form> </div> <?php } else { ?> </div> <!--Begin Sub-Navigation. This only appears when a user is logged in.--> <div class="container1"> <div class="menu1"> <div class="sub-nav"><a href="../index.php"></a> <img src="../themes/default/images/arrow-red.jpg" style="vertical-align:middle" alt="" /><a href="../members/[var.user_name]"> my account</a><img src="../themes/default/images/arrow- red.jpg" style="vertical-align:middle" alt="" /> <a href="../credits.php">[var.lang_my_credits]: [var.member_credits]</font></a><img src="../themes/default/images/arrow-red.jpg" style="vertical-align:middle"><a href="../logout.php">[var.login_out]</a> <!--[onload;block=div;when [var.loggedin]=1;comm]--> </div> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491838 Share on other sites More sharing options...
Chrisj Posted September 23, 2014 Author Share Posted September 23, 2014 thanks for your reply. I plugged in your code that you "switched around a little" and after logging in I was re-directed to the /myaccount.php page. Although i appreciate your help, that isn't what i was hoping for. The code that shows in my initial post, logs-in successfully (from the home page) and then shows the sub-menu things on the home page. (But it also shows the log-in Form still on the homepage). I'd like to stay on the home page (with the sub menu stuff)and not be re-directed (but just have the log-in form disappear after succeeding). Any additional help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491846 Share on other sites More sharing options...
QuickOldCar Posted September 23, 2014 Share Posted September 23, 2014 action="../login.php" is where it goes once the form is submitted. You will need to change the redirect location in login.php to the home page instead of myaccount.php if that's where you want to go. Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491854 Share on other sites More sharing options...
Chrisj Posted September 23, 2014 Author Share Posted September 23, 2014 Thanks for your reply. The re-direct now goes to index.php, thanks. However, the Login Form (and sub menu) still reappears on the home page once it succeeds. Any help I can get to have the log-in form disappear and only reappear upon log out, will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491859 Share on other sites More sharing options...
Strider64 Posted September 23, 2014 Share Posted September 23, 2014 (edited) It an utilities file that I have on each page I have this // Check for a user in the session: $user = (isset($_SESSION["user"])) ? $_SESSION["user"] : NULL; Of course when you login you would put the user in session, then I simply do this where I have my login/logout (Logout is simply taking the user out of session) If ($user) { /* Logout Script */ } else { /* Login Script */ } Edited September 23, 2014 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491864 Share on other sites More sharing options...
Chrisj Posted September 23, 2014 Author Share Posted September 23, 2014 Thanks for your reply, but I'm sorry I don't know how/where I can use that. Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491866 Share on other sites More sharing options...
mac_gyver Posted September 23, 2014 Share Posted September 23, 2014 When I asked how to make this Log In Form disappear once it performs it's function: I was given this line of code: if($_SESSION['loggedin'] == true){ //dont show form } else { //show form } But I don't know how/where to integrate it into the Form.Any help will be appreciated. that particular piece of information is incorrect. there is no session variable in your script by that name. whoever suggested it was just guessing and it's not possible to write code that does what you want unless you have 100% accurate information. the session/logged in code does however set a variable $loggedin = 1; when the $_SESSION['user_id'] is not empty. this is why it is important when programming to actually read the code you are using, rather than to depend on other people to tell you or to guess about things it is doing, so that you don't waste days on a task that only takes a couple of minutes. you didn't however answer any of the questions i asked in the first reply in this thread. does php code even work in the template files where the log in form is at? i'm guessing it doesn't and you must use the template's methods to cause sections to be displayed or not. Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491868 Share on other sites More sharing options...
ginerjm Posted September 23, 2014 Share Posted September 23, 2014 You do realize that things that 'appear' on your screen are being put there by You, ie, Your Script. So - if you don't want them to appear, Don't Send Them. Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491873 Share on other sites More sharing options...
LeJack Posted September 23, 2014 Share Posted September 23, 2014 (edited) Thanks for your reply, but I'm sorry I don't know how/where I can use that. It's simple. Just place If ($user) { /* Logout Script */ } else { /* Login Script */ } Where your login form was. Place your login form inside the else statement and then put what ever you want in the if statement. If you want us to give you the answers, you won't learn anything. Edited September 23, 2014 by LeJack Quote Link to comment https://forums.phpfreaks.com/topic/291225-how-to-make-the-log-in-form-disappear-after-succeeding/#findComment-1491877 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.