You are here: Re: making FORM dissapear when successful login « PHP « IT news, forums, messages
Re: making FORM dissapear when successful login

Posted by JHollis on 01/06/05 05:49

Where do i need to start my session? Ive copied and pasted exactly what
you have typed..and the form doesnt display unless i hard code the
variable to "NO".

Jerry Kita wrote:
> I do exactly the same thing on my website. I use PHP's Session handling
> to determine if a user is actually logged on.
>
> You can see that I check a variable called $validlogon which I set to
> either YES or NO at the beginning of the script
>
> <?php
> if ($validlogon == "NO") {
> print "<p class=\"hnavbar\">Salkehatchie Members Login Here:<br>\n";
> print "<form action=\"Salkehatchie_LoginScript.php\" method=\"POST\">\n";
> print "<p class=\"login\"><small>USER ID:</small><br>\n";
> print "<input type=\"text\" name=\"userid\"><br><br>\n";
> print "<small>PASSWORD:</small><br>\n";
> print "<input type=\"password\" name=\"password\"><br><br>\n";
> print "<input type=\"submit\" value=\"Enter\"></p>\n";
> print "</form>\n";
> }
> ?>
>
> Near the beginning of my script I check for the existence of a valid
> session
>
> <?php
> if (isset($_SESSION[userid])) {
> $validlogon = "YES";
> } else {
> $validlogon = "NO";
> }
> ?>
>
> Setting the $validlogon variable allows me to do a number of useful
> things. For example, there are certain parts of the webpage that I
> reveal to logged in users. Checking $validlogon allows me to decide
> dynamically what to render to the browser. In the following I display
> a message showing the user as being logged in and give them a link that
> logs them out.
>
> if ($validlogon == "YES") {
> print "<table style=\"width: 100%\";>\n";
> print "<tbody>\n";
> print "<tr>\n";
> print "<td width=\"50%\"><p class=\"login\"><small><b>YOU ARE LOGGED
> IN AS: $_SESSION[userid]</b></small></p></td>\n";
> print "<td width=\"50%\"><p class=\"login\"><small><b>CLICK <a
> href=\"LogoutScript.php\"> here</a> TO LOGOUT</b></small></p></td>\n";
> print "</tr>\n";
> print "</table>\n";
> }
>
> Hope this is helpful
>
> Jerry Kita
>
> JHollis wrote:
>
>> I had this code working the way i wanted it to (as far as correct
>> username and password allowing successful login)...but what i want to
>> happen now is when a user successfully logs it it will make the login
>> form disappear and just say successfully logged in or welcome user and
>> a link below it so they can log off and make the form re-appear.
>> Below is the code that i have where i tried to get it to disappear on
>> successful login, but it stays disappeared all the time. Can someone
>> please point out what im doing wrong. I have tried everything i can
>> think of...and nothing works. Im a PHP newbie...so im sure some of
>> you might get a laugh out of this...if it is real easy.
>>
>> <---snippet
>>
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>> <html>
>> <head>
>> <link href="style.css" rel="stylesheet" type="text/css" />
>> </head>
>> <body>
>> <div id="container">
>> <div id="top">
>> <h1>header</h1>
>>
>> </div>
>> <div id="leftnav">
>> <p>
>>
>> <?php
>>
>> $username=$_POST['username'];
>> $password=$_POST['password'];
>> $db="user";
>> $server="localhost";
>> $db_username="root";
>> $db_password="*******";
>> $connect = mysql_connect($server,$db_username,$db_password);
>> if (!$connect) {
>> die ("could not connect to database");
>> }
>> $select = mysql_select_db($db,$connect);
>> if (!$select) {
>> die ("could not select database $db");
>> }
>> /*username='$username'";*/
>> $sql = "SELECT * FROM passwords, user_info where id=PID and
>> username='$username'";
>> $result = mysql_query($sql);
>> /*$num_rows = mysql_num_rows($result);*/
>> while ($user = mysql_fetch_array($result))
>> {
>> $id = $user['id'];
>> $username2 = $user['username'];
>> $password2 = $user['password'];
>> $firstname = $user['firstname'];
>> $email = $user['email_address'];
>> IF ($username=="$username2" && $password=="$password2")
>> {
>> echo("\"Welcome, <b>$firstname</b>\"");?><br><?
>> echo ("\"Your email address is <b>$email<b>\"");?></td><tr>
>> <a
>> href="<?$_SERVER['PHP_SELF']?>?username=""&?password=""">Logoff</a><?
>> break;
>> }
>> else
>> {
>> ?>
>> <FORM action="<?$_SERVER['PHP_SELF']?>" method="post">
>> <INPUT type="hidden" name="id">
>> <table>
>> <td><b>*</b>Username:</td> <td><INPUT class="input"
>> size="8" type="text" name="username" value="<?echo $username?>"></td><tr>
>> <td><b>*</b>Password:</td> <td><INPUT class="input"
>> size="8" type="password" name="password"></td><tr>
>> <td class="xsmall"><b>* Case Sensitive</b></td>
>> <td><INPUT type="submit" value="Login"></td><tr>
>> <td>&nbsp </td>
>> </table>
>> </FORM>
>> <?
>> break;
>> }
>> } //IF ($username != $username2 || $password !=
>> $password2) {//
>>
>>
>> ?><br>
>> <?
>> if ($username == "" && $password == "") {
>> echo ("Please type in a Username and Password");}
>>
>> if ($username != "" && $password == "") {
>> echo ("Please type in a password");}
>>
>> if ($username == "" && $password != "") {
>> echo ("Please type in a username and password");}
>> ?>
>> </p>
>> </div>
>> <?if (($username2==$username && $password2==$password) &&
>> ($username2!="" || $password2!="")){?>
>> <div id="rightnav" class="box">
>> <p>
>> </p>
>> </div>
>> <?}?>
>> <div id="content">
>> <h2>Subheading</h2>
>> <p>
>> </p>
>> <p>
>> </p>
>> </div>
>> <div id="footer">
>> <p>
>> Today is
>> <?php
>> echo( date("F dS Y."));
>> ?>
>> </p>
>> </div>
>> </div>
>> </body>
>> </html>
>> ---->snippet
>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация