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

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #18) by fffanatics on May 25 2005, 11:03 AM. (Line Breaks Removed)
Yes my code does work and i do actually use cookies. I use to cookies so that they have the option of not having to sign in for 2 weeks. However, this is the only information that is cantained in the cookie. Personally, i like sessions cause its very easy to use and is a secure way to send and recieve information from a page... read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

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

fffanatics
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.

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.

 

 

 


Reply

mbd5882
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:
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>




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.

 

 

 


Reply

fffanatics
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

Reply

mbd5882
NO WAIT, SORRY! ohmy.gif
Put this on your index page,

-----------------------------------------------------------------------------------------------
CODE

<?

   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 [code][/code] tags to put in codes again, you will lose your facilities here!

Reply

mobious
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.

Reply

fffanatics
QUOTE
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.

Reply

mobious
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.

Reply

alexia
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
CODE
<?php
<?php
if(!$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 biggrin.gif

Reply

fffanatics
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?

Reply

candicej
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:
CODE

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


In checkuser.php, after all variables have been checked and the user verified, I have this:
CODE
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

Reply

Latest Entries

fffanatics
Yes my code does work and i do actually use cookies. I use to cookies so that they have the option of not having to sign in for 2 weeks. However, this is the only information that is cantained in the cookie. Personally, i like sessions cause its very easy to use and is a secure way to send and recieve information from a page

Reply

Mike
Why not just use cookies to keep your users logged in? It's a lot easier using sessions, in my opinion. All you would have to do is add a new variable to the config file that is something like this:

CODE


$username = (isset($_COOKIE['user']) ? $_COOKIE['user'] : Guest);



login.php

CODE


<?php

# Include all the needed files

if (isset($_POST['login'])) {
   $uname = $_POST['username'];
   $pword = $_POST['password'];
   $check = mysql_query("SELECT username FROM users WHERE username='$uname' AND password='$pword'") or die(mysql_error());
   if (mysql_num_rows($check) == 0) {
        echo 'Invalid username or password';
        exit;
   } else {
       setcookie('user', $uname, time()+999999);
       setcookie('pword', $pword, time()+999999);
       echo 'You have successfully logged in!  Return to the <a href="/">index</a>.';
   }
} else {
   echo '';
   }

?>


Reply

fffanatics
Hey everyone thanks for your help. My login script works 100% now. The error was because i had a blank line after the ?> in the one file i included. Thanks for all of your great ideas and solutions

Reply

fffanatics
Hmmz thanks for the help but i am not looking to really rewrite a good amount of my code. I just was wondering if anyone knew how i could fix this error since it must be a small one if i dont get it on my server but do get it on the trap17 one

Reply

HmmZ
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:
CODE

<?
$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? blink.gif


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. php script webspaceorder - 505.56 hr back. (1)
  2. "email sign up" script squirrelmail - 723.48 hr back. (1)
  3. open_basedir restriction in effect. file(./user.log) is not within the allowed path(s): - 780.15 hr back. (2)
Similar Topics

Keywords : php, login, script, removing, login, field, user, logs

  1. How To Make Php Newsletter Script
    (3)
  2. Php Guest Online Script
    (3)
    make an index.php copy and paste this code CODE <?php $db_host = "localhost";
    $db_user = "root"; $db_pass = ""; $db_name = "test";
    $dbc = mysql_connect($db_host, $db_user, $db_pass); $dbs =
    mysql_select_db($db_name); $tm = time(); $timeout = $tm -
    (30*60);
    if($_SERVER["REMOTE_ADDR"]){$ip=$_SERVER["REMOTE_ADDR
    "];} else{$ip=$_SERVER["HTTP_X_FORWARDED_FOR"];}....
  3. How To Make A View New Post Script?
    (5)
    Ok so i'm still working on the forum software i posted about a while back, but I have no idea
    how to do this. I want to make a view new post script, as this is one of the main things that my
    forum software dose not have that all other forums have. so does any body have an idea on how i
    would do this? Thanks.....
  4. Guessing Php Script
    (2)
    I am looking for: freeware php quess the person in the photo game script....
  5. Unexpected T_string In User.php [resolved]
    (5)
    Ok so i'm working on a site for my chruch, and i seem to be having a little bit of trouble with
    the user.php file i keep getting the following error: CODE Parse error: syntax error,
    unexpected T_STRING in /home/darkzone/public_html/test/user.php on line 195 and i was wondering
    if some one could help me with the script. session_start(); ob_start(); //Include the
    configurations include('config.php'); //Define a few variables $x = $_GET ;
    $u = $_GET ; class register { function displayform($title) { echo('....
  6. Need Help Installing Dolphin Community Script!
    (5)
    I'm not sure if this is the right place to post this but I really need help in installing the
    dolphin community script. I have absolutely no previous experience of scripts or programming. I
    would really appreciate if someone could walk me through it step-by-step, or even do it for me by
    logging into my cpanel. I have tried to install it my self but I'm a little confused. I'm
    sure it won't take very long at all for someone who has done this before.....
  7. How Do I Connect To Live Database With Php Script?
    while being hosted with ComputingHost (6)
    I am not new to programming. I want to create a form to add some values into my tables, the code
    are all working. But I am not sure what is the URL to connect to my site's database. All along,
    I have been testing through MAMP, which provides a local copy of mySQL. Can anyone lend me a hand?
    My site's URL is http://limetouch.com/ ....
  8. Download Script For Mp3 Files
    (0)
    Hello, I'm looking for a download script for sound files (e.g. mp3, avi, wma, and other ones).
    i have found a few download scripts but they would not work for sound files for some reason. also
    this will not be used for allowing downloading of illegal or riped music, what i will be using this
    script for is i'm making a site for my church and the pastor wants to be able to recored the
    services and then have me upload them to the site so that the church members can download them for
    what ever reason. If some one could tell me how to make one or could show me a plac....
  9. Php Rediret Script
    (12)
    Ok, what I am trying to do is this. Re-direct a domain name called: avalon.asn.au to
    preschool.stmarksavalon.org.au I have created a script that will re-direct within the a folder.
    However, the avalon.asn.au and stmarksavalon.org.au are PARKED Domains. Any ideas on how to create
    this PHP Redirect Script please?....
  10. Forum Script
    (3)
    Hello, i'm wanting to start making my own forum software but i dont know where to start or what
    i need to know in order to do this. I know i will need php and mysql but what else, and could some
    one point me to a good site were i could learn php and mysql. Thanks ....
  11. How Would I Go About Making A Simple "counting" Script?
    (3)
    I plan on making a script for basic voting between different options, and I'd like to know what
    PHP coding I would require. Basically, each choice will be as simple as this: CODE <form
    method="post" action="process.php"> Best falsetto?<br><br>
    <input type="radio" name="1"> Person A<br> <input
    type="radio" name="2"> Person B<br> <input type="submit"
    value="Submit"> </form> What PHP would be used to basically add 1 value to a....
  12. Library Script
    Where? (6)
    Hello, everyone. Anyone knows where I can get a library script that acts like CMS script software,
    you can add books or delete them. I want to build virtual online library which can be accessible to
    everyone. Or just give me some advices how to make it build. I'm a novice in programming.....
  13. Php Ftp Upload Form
    Adding User Directory to PHP Upload Form - Help (1)
    Alright I am trying to have a PHP FTP Upload Form that allows the user to create the directory
    folder for where they want to upload there files to. example: Main Directory: vainsoft.com There
    directory: vainsoft.com/modeling or vainsoft.com/photography But I dont want them to be able to
    upload things into the main directory, only sub-directories, is that possible with this coding that
    I have: //uses $_FILES global array //see manual for older PHP version info //This
    function will be used to get the extension from the filename function get_extension($fi....
  14. One Login Account At One Time
    (3)
    When we login, we got a session. But at the same time when we still login, another one could login
    at our account. So, can we restrict only one user could login at one account? So if another wants
    to log into the same account, he must wait until the one logs out. Thanks in advance.....
  15. Script Not Working
    I don't know why. (6)
    For some reason my random string script is not working. I got a fatal error when I tried it under
    XAMPP. I do not know why. It looks syntatically correct. Could someone help me? Here is the script:
    (Warning its over 100 lines long) //This PHP script will generate a random array and turn it into
    a string consisting of 0-9 and A-Z. // This is the first developmental version. //Create 10 item
    array for string $string = array(0,0,0,0,0,0,0,0,0,0); //Create function to replace 10-36 with
    A-Z function conToStr() { for ($a = 0;$a switch($string ) { ....
  16. Script Help Required: Undefined Variable
    A fault I cannot spot in PHP (3)
    Hi, when running a PHP script I keep getting the error: QUOTE Notice: Undefined variable: bret
    in c:\program files\easyphp1-8\home\poll.php on line 294 Notice: Undefined
    variable: bret in c:\program files\easyphp1-8\home\poll.php on line 294 (And,
    yes, I get it twice). The code related to the variable is as follows: CODE function
    LogString($string,$type)     {         $t_log = "\n";
            $t_log .=
    $this->globaldata->server_vars['REMOTE_ADDR']."....
  17. Php Downloads Script
    (4)
    I've been looking all over the net for a PHP script which can provide an interface to browse a
    downloads database. The database could be powered by MySQL. If you know a script like this, please
    post it here. Thanks in advance, Ironchicken.....
  18. Will This Code Work
    php linking script ?p= (5)
    hi i'm not that great at php so i'm not to sure if this will work or not. but what i want to
    do is be able to use ?p=staff or what ever page name, with out the php extion, and i would like to
    no if this simple script i made would work. the code is: CODE <?php $p =
    $_GET['p']; if ( !empty($p) &&
    file_exists('./' . $p . '.php') && stristr( $p, '.'
    ) == False ) { // pages = directory where you store your pages    $file = './'
    . $p . '....
  19. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE <?php //Save this as something like htmltest.php function
    CheckForm() { $html_unsafe=$_POST['code']; //Gives us our user
    input $html_safe=str_replace("<?php"," ",$html_unsafe);
    //Starts security measures $html_safe=str_replace("?>","
    ",$html_sa....
  20. Very Simple Online Now Script
    This is a very simple online now script. (4)
    Hi all, Its Aldo. anyways, I wont be using the method of pagination, i will just tell you how to
    make a basic online now script. When someone logs in, now take into consideration that the name of
    the username input is username ( First ,create a table in your database saying online now and add 2
    fields to it. id and username CODE id type=integer(INT) , auto increment, length =255
    and username = VARCHAR length=the limit a username should be in your site now from there we take
    off : CODE <?php //logged.php //authentication script //connection scri....
  21. Creatting A Playlist Through Php
    script help needed (5)
    Hi I am trying to make a script so that i can insert songs into a playlist, but i need a script in
    which it opens the playlist file and removes the closing tag at the end, so before i can add more
    entrys. e.g CODE <atx> <entry>Location 5</entry> <entry>Location
    4</entry> <entry>Location 3</entry> <entry>Location
    2</entry> <entry>Location 1</entry> <atx> But to add more entrys
    i would have to get rid of the atx, then use the fputs to place the new entry into the file. ....
  22. What Kind Of Script Do You Need ?
    post here and get free script (15)
    Hi everybody sorry if i posting here , i know I want design free PHP script and i dont know
    webmasters what kind of scripts want i think its better to aks here becuase trap17 is very nice
    webmasters forum So , Plz post here what kind of script with details you need ! sorry may en
    is not very well for example you need "upload center" : write "upload center" with upload center
    options ( like Ajax , Fast , multi lan and ... ) with this post we can give script details and
    webmasters idea /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.....
  23. Wappy Buddy V1.10 - Tibia Gold Edition By Wappy & Jon Roig
    the official wap download script (3)
    By downloading this script you are agreeing to the license and terms outlined below /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> QUOTE /** * *
    @package: wappyBUDDY - Tibia Gold Edition * @version: 1.10 2006/10/01 00:00:01 wappy * @copyright:
    ©2003, 2006 jon roig, wappy * @release notes: this is the first official release of my download
    script despite pirate and incomplete copies floating around that were stolen from one of my previous
    servers. The next release will follow very shortly * @terms: wappyBUDDY is free softw....
  24. Free Auction Script
    Any Suggestions? (6)
    Any free auction script suggested? I want it to be as many practical functions as possible, yet
    easy to manage. And more importantly, it is free! Appreciate your kind suggestions!....
  25. Wappychat_oldskool
    old version of my wap chat script :-) (15)
    here is a very old version of my wap chat script, its not very advanced but has privates, smileys
    etc. I will post some further versions (with owner, admin, mod status and profiles) when i have time
    to write the readme/install instructions for them. You will find instructions inside the zip. If you
    have any problems post here but i know it don't work on all servers for some reason but it does
    work on the trap server so will be cool ok /tongue.gif" style="vertical-align:middle" emoid=":P"
    border="0" alt="tongue.gif" /> ....
  26. Watermark Your Image With Simple Php Script
    found it on the net (35)
    This script was found on the net http://tips-scripts.com/?tip=watermark#tip B&T's Tips &
    Scripts site. Just in case the site may not show, I will include the code here: List of things
    needed: 1. your image in any format 2. watermark image--in gif format with transparent background 3.
    script below with name (i.e. watermark.php) CODE <?php // this script creates a watermarked
    image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly
    transparent gif image with the watermark - goes in the same directory as this script // ....
  27. Transfer Variables To Another Php Script
    (8)
    Hello, I've one registration page where the users fills in their information, is it possible to
    trasnfer the things the fill in on the registration page to another script that does someting and
    returnes something to the first page like true/false and then the registration gives an error
    messange if the other php script returned false? Something like the script "activates" another
    script that does something and returnes the result back to the original script. Best Regards ....
  28. Parse: Error Unexpected T_lnumber
    php parse error when running script (4)
    Hi. I've just created a php script. The main object of the script is to delete some old files
    and replace it with a new file with some new content, effectively moving the contents from one file
    to another. These are the first 50 lines of the file: /* Calculate For The "A" Group - The
    Latest Games ID */ $a_B = 002; while(file_exists("a_" . $a_B . ".dat")) {
    $a_B++; } $new_page_contents = " " . $_POST . " " . $_POST . "
    include \"/home/cmatcme/public_html/footer.php\"; ?> "; $a_stream = fopen(&....
  29. Script: Php Jukebox
    A one file script! (4)
    This scripts is so simple, you dont need to edit ANY of it! All you have to do is make a folder
    called 'songs' and put some audio files in it. Here is the whole page, I named it index.php
    and put it in a folder called 'music': CODE <!DOCTYPE HTML PUBLIC
    "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
    <title>PHP jukebox</title> </head> <body> <!-- ©2005 Craig
    lloyd. All rights reserved. Visit cragllo.com for more sc....
  30. Many Php Script Sites
    (16)
    Hi I find many sites has PHP scripts :: http://www.proxy2.de/scripts.php http://www.free-php.net
    http://knubbe.t35.com/ http://www.ngcoders.com/ http://www.oxyscripts.com/
    http://www.phparena.net/ http://www.1phpstreet.com/ http://px.sklar.com/
    http://www.scoznet.com/ http://php.resourceindex.com/ /blink.gif' border='0'
    style='vertical-align:middle' alt='blink.gif' /> ....

    1. Looking for php, login, script, removing, login, field, user, logs

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for php, login, script, removing, login, field, user, logs

*MORE FROM TRAP17.COM*
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE