Jump to content

How to make the Log-In Form disappear after succeeding


Chrisj

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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();
Link to comment
Share on other sites

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
}
?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Strider64
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by LeJack
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.