Webmaster Forum


Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 07-29-2012, 06:22 AM
Junior Member
 
Join Date: 07-29-12
Posts: 1
iTrader: 0 / 0%
Php login help

Hello everyone, I am very new to PHP and I am having difficulty with my login. I can do standard logins via directing to another page, however this one is different.

I would like a login section at the top of my website which is always displayed. If your not logged in then it would always show the login boxes, if you are logged in then it would always display logout. I am also using sessions once you have logged in. I have a feeling I need a loop.

I am rubbish with if and else as I am new to all of this so I appologise if the mistakes are simple. One of the problems I am having is that the messages are being displayed on a seperate page rather than with the rest of my website.

This is what I have so far:

PHP Code:
<?php
include('../includes/config_inc.php');

if(isset(
$_SESSION["username"])) {
echo
" <a href='../admin/logout.php'>Logout</a>";
}

else {

    echo
" <form method='post'>";
    echo
" <label for='username'>Username</label>";
    echo
" <input type='text' name='username' id='username' />";

    echo
" <label for='password'>Password</label>";
    echo
" <input type='password' name='password' id='password' />";

    echo
" <input type='submit' name='submit' value='Log in' />";

    echo
" </form>";    //Puts in form if not logged in
    
    
echo" <a href='../admin/register.php'>Register</a>";

//form validation
if(!isset($_POST['submit']))  //if the form has been filled out
{

$username $_POST["username"];
$password md5($_POST["password"]);

$authenticate mysql_query("select * from customer where username='$username' and password='$password'");


if(
mysql_num_rows($authenticate)==1)


{
$_SESSION["username"] = $username;

echo 
"Hello $username";  // a session created


}
else
{
    
//a session not created, displays form again with login incorrect message
}
}}

?>

Last edited by snakeair; 07-29-2012 at 06:32 AM.
 
Reply With Quote
  #2 (permalink)  
Old 07-29-2012, 08:17 PM
Super Moderator
Latest Blog:
None

 
Join Date: 11-11-11
Location: Copenhagen, Denmark
Posts: 1,857
iTrader: 0 / 0%
You're on the right track, there seems to a mistake with:
PHP Code:
if(!isset($_POST['submit']))  //if the form has been filled out 
It's probably suppose to be without "!":
PHP Code:
if(isset($_POST['submit']))  //if the form has been filled out 
From a security point of view, you need to look in to:
If you use PHP 4.3 or higher:
string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier = NULL ] )

If you use a lower version of PHP, take look at:
string addslashes ( string $str )

Since your script is not secure from mal-ware injections.
__________________
Need a break? EnterCave more than 40000 online games in 15 categories.
Search or browse through EnterCave Online Games Directory
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Site login and phpBB login SVB Coding Forum 13 08-02-2004 06:32 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 09:40 PM.
Powered by vBulletin
Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.