Jump to content
xisto Community
fffanatics

Php Login Script Removing the login field once the user logs in

Recommended Posts

Hey everyone. I have a login script that i know works. My question is that on my main page, it have a form to allow the user to log in. What i want it to do is that once the user logs in, the form disappears and the users data (aka username) is displayed where the form was. At the moment i cant get it to work. Below is my code.

<div id="loginMenu">  <?php    if ($logged_in == 1)    {  ?>     <!-- User information -->  <?php     }//if     else     {  ?>    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">   <table border="0" cellspacing="1" cellpadding="0">      <tr><td>Username: </td></tr>      <tr><td><input type='text' name='uname' size='17'></td></tr>      <tr><td>Password:</td></tr>      <tr><td><input type='password' name='passwd' size='17'></td></tr>      <tr><td><input type="submit" name="submit" value="Login"> <input type="submit" name="submit" value="Register"> </td></tr>   </table></form>    <?php   }//else?></div>

What happens with this code is that it only will display the form because the user isnt logged in. If i refresh the page in IE it will then display it. There has to be a way to dynamically change it once the user submits the form. THanks for the help

Notice from snlildude87:
Use code tags for code. This is your warning.

Edited by snlildude87 (see edit history)

Share this post


Link to post
Share on other sites

I think you need a tag,

Or one of those other thingies which ashs a question,

 

 

Is user logged in?

 

Yes:

Welcome [username.]

 

No:

Display:

<div id="loginMenu"><?phpif ($logged_in == 1){?><!-- User information --><?php}//ifelse{?><form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"><table border="0" cellspacing="1" cellpadding="0"><tr><td>Username: </td></tr><tr><td><input type='text' name='uname' size='17'></td></tr><tr><td>Password:</td></tr><tr><td><input type='password' name='passwd' size='17'></td></tr><tr><td><input type="submit" name="submit" value="Login"> <input type="submit" name="submit" value="Register"> </td></tr></table></form><?php}//else?></div>

 

Google it, On what whe script is, Or ask an admin.

I need a login page for my sit too, & in the end i just gave up.

 

Thanks,

FFC Webmaster,

Asad Haider.

 

Notice from snlildude87:
Use code tags for code. This is your warning.

Edited by snlildude87 (see edit history)

Share this post


Link to post
Share on other sites

OK thanks for the reply and sorry about not using the code tag. i didnt even notice that it was a tag so sorry. What i was asking was that it would display the login box in the loginMenu div but once the user hits submit in the form, that the user logs in (which my script works) and then instead of showing the loginMenu, it would display the users information. Thats what the if (loggedIn) was for but what i think happens is when the user logs in, the page isnt refreshed so it doesnt even see whats in the if.Hopefully someone can help. Thanks agian and sorry about not using the code tag

Share this post


Link to post
Share on other sites

NO WAIT, SORRY! -_-
Put this on your index page,

-----------------------------------------------------------------------------------------------

<?    session_start();    $uid = $_SESSION['uid'];    $pwd = $_SESSION['pwd'];	require('main.php');	db_connect();	include(INC_DIR."header.php");  if ($uid){  	echo "<br>already logged in";  } else {  	echo "<br><Span Class=emph>Members Log In</SPAN>";      	include(INC_DIR."login.php");  	echo "<Span Class=emph>Not a Member? Join Now!</SPAN>";      	include(INC_DIR."signup.php");  }	include(INC_DIR."footer.php");	db_disconnect();?>


-----------------------------------------------------------------------------------------------

Without the dashes, Youll have to configure all the variables, Like
'include(INC_DIR."footer.php");'


THIS IS DEFINETLY RIGHT, USE THIS BUT YOULL HAVE TOO DO IT.
Sorry for the mix-up.


Thanks,
FFC Webmaster,
Asad Haider.

Notice from Googlue:
This is your FINAL WARNING!!!
If you do not use tags to put in codes again, you will lose your facilities here!

Edited by googlue (see edit history)

Share this post


Link to post
Share on other sites

i think fffanatics already has his own auth system. and his code works. i think it's with $logged_in not beeing assigned with the right value.

Share this post


Link to post
Share on other sites

i think it's with $logged_in not beeing assigned with the right value

Yeah i know my auth system works cause i can produce a login script that works when on a separate page. However, who wants to change pages just to log in. It has to be with teh $logged_in variable. This is the order of operations that need to happen along with which ones work:

1.) Users enters fffanatics and decides to log in using the form (works - it is the else)

2.) THe user hits submit and is authenticated (works)

3.) Now instead of the form still being on the page, it should display the users information instead (doesnt work)

I just cant seem to get to form to go away after the user hits submit. Hopefully this clarifies the issue.

Share this post


Link to post
Share on other sites

i belive that there is no way you can gather all the data about the user when he logs in and then display it with out another page or a script processes it. you have to make your script log the user in then redirect it again to the page with his details displayed.

Share this post


Link to post
Share on other sites

I write this Easy Login in php and i want to learn to you how to write easy password login its sample of my code its not a user pass login

<?php<?phpif(!$action){print ("<body bgcolor='#ffffff'>Admin Panel - Set Quiz ::<P><form name='forum2' method='post' action='$PHP_SELF'><p>Password  <input type='text' name='password' size='20'><P><input name='Submit2' type='submit' value='Quiz'> </form>");$max = "my password"; if ($password == $max){print ("<body bgcolor='#ffffff'>Admin Panel - Set Quiz ::<P>---- ///And then you can post and write your html tags of your html page here for display when password is true\\\\");}?>
its really easy
i write this password login for my online exam -_-

Share this post


Link to post
Share on other sites

OK so if i understand all of you correctly, what i should do is have the user log in (run my log in script) and then redirect them to the correct page that would contani their information?

Share this post


Link to post
Share on other sites

I have my website set up that after you go to the index page, you must log in to go futher. Once you log in, you are directed to another index page with a Welcome! script and member-specific info. When you set up your form to process, direct the form to a processing page that verifies your user then directs to a welcome page (a copy of your index) and modify that page to whatever welcome content you wish!

This is my form processing code:

<form action="checkuser.php" method="post">

In checkuser.php, after all variables have been checked and the user verified, I have this:
if($login_check > 0){    while($row = mysql_fetch_array($sql)){    foreach( $row AS $key => $val ){        $$key = stripslashes( $val );    }        session_register('first_name');        $_SESSION['first_name'] = $first_name;        session_register('last_name');        $_SESSION['last_name'] = $last_name;        session_register('email_address');        $_SESSION['email_address'] = $email_address;        session_register('special_user');        $_SESSION['user_level'] = $user_level;        $_SESSION['auth'] = true;                mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");                header("Location: welcome.php");    }} else {    echo "<center><font color=red><strong>You could not be logged in! Either the username and password do not match or you have not validated your membership!<br />    Please try again!</strong></font></center><br />";    include 'index.php';}

I hope some of this helps you. I know that was a huge chunk of code for just a little info, but I was afraid of leaving out something you might need. Good luck!

candicej

Share this post


Link to post
Share on other sites

OK so if i understand all of you correctly, what i should do is have the user log in (run my log in script) and then redirect them to the correct page that would contani their information?

138404[/snapback]


yes, you got what i meant.

Share this post


Link to post
Share on other sites

Well i got my login script and everything like that working on my own server running apache and php 5.0 but now that ive uploaded it when i try to register or login i get errors.

If i can fix the register problem, i think the rest will be fixed too. So when i click the register button it is supposed to take me to the register page. However, instead i get this message "Warning: Cannot modify header information - headers already sent by (output started at /home/ffanat/public_html/db_connect.php:7) in /home/ffanat/public_html/loginCheck.php on line 4"

I know that this is a message that is used it anything at all has been writen to the page already when the function was called but i dont get why it works on my computer. I know it is one of these 3 includes that i have in my index page at the top of the page.

Index top relevant information:

<?php	session_start();    include 'db_connect.php';    include 'member_class.php';	$member_class = new member_class;	include 'loginCheck.php';?> 

db_connect
<?php  /**   * Connect to the mysql database.   */  $conn = mysql_connect("localhost", "*****", "*****") or die(mysql_error());  mysql_select_db('ffanat_users', $conn) or die(mysql_error());?> 

and loginCheck.php
<?php	if ($_POST['Register'])	{  header('Location: register.php');	}//if    elseif ($_POST['Login'])      	{        $username=$_POST['username'];        $password=$_POST['password'];        if ($username && $password)   {            if($_POST['remember'] ==1)      	{            	$member_class->check_login($username, $password, true);            }//if  	else  	{            	$member_class->check_login($username, $password, false);            }//else      	}//if      else   	$member_class->message .= 'Please fill a username and password.';    }//else if    elseif($_POST['Logout'])   	{       $member_class->logout();    } ?>

Hopefully someone can tell help me fix this problem. If you want to see if first hand just go here: http://forums.xisto.com/no_longer_exists/ and click register. Thanks everyone for helping me sooo much.

Share this post


Link to post
Share on other sites

OK i just realized that the way i did the code tags on the previous post it shows a blank space before the code but those are not in my actually files so ignore them

Share this post


Link to post
Share on other sites

Instead of directing the user to the registration page right away , you could just echo that they are not registered and then give them a link to the registration page.

I am a newbie php'er, but:

<?$register=$_POST['register'];$login=$_POST['login'];if($register){echo "Please register first";header("location: register.php");}else {if($login){$username=$_POST['username'];$password=$_POST['password'];$remember=$_POST['remember'];}if($remember==1){           $member_class=check_login($username, $password, true);echo "succesfully logged in, redirecting you";header("location: membersarea.php");}else {            $member_class=check_login($username, $password, false);echo "The username and/or password you provided is wrong";header("location: login.php");}$logout=$_POST['logout'];if($logout){           $member_class=logout();}}

Its probably completely wrong (doh!) but it was worth a shot, what i dont understand is the use of ->, is that actually php? :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.