Current location: Hot Scripts Forums » Programming Languages » PHP » sessions problem


sessions problem

Reply
  #1 (permalink)  
Old 07-23-03, 06:49 AM
superman's Avatar
superman superman is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
sessions problem

i use this code to verify the username & password, but how to pass the username in every pages such as 'welcome andy' if andy login and 'welcome jack' if jack login.
this script is unsecure, what script should i include in every pages so when i enter http://localhost/payroll.php it will ask me to login first.


<?
session_start();
if ($username && $password)
{
$Connect = mysql_connect("localhost", "root", "");
mysql_select_db("mw");
$result = mysql_query("select * from account where username='$username' and password='$password'");

if (mysql_num_rows($result) > 0)
{
$valid_user = $username;
session_register("valid_user");
}
}
?>


<?
if (session_is_registered("valid_user"))
{

$_SESSION['valid_user'] = $_POST['username'];
echo "<center><br><br>You are logged in as: $valid_user <br><br>";
echo "<center><a href=\"logout.php\">Log out</a><br>";
}
else
{
if (isset($username))
{
echo "<center>Could not log you in";
}
else
{
echo "<center>You are not logged in.<br>";
}
echo "<form method=post action=\"login.php\">";
echo "<center><table>";
echo "<tr><td>Username:</td>";
echo "<td><input type=text name=username></td></tr>";
echo "<tr><td>Password:</td>";
echo "<td><input type=password name=password></td></tr>";
echo "<tr><td colspan=2 align=center>";
echo "<input type=submit value=\"Log In\"></td></tr>";
echo "</table></form>";
}
?>
Reply With Quote
Reply

Bookmarks


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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
file download problem ukyankee Perl 6 10-04-03 10:39 PM
PHP & sessions, why won't it work? TinnyFusion PHP 1 10-04-03 01:51 PM
session problem afkaar PHP 0 08-27-03 04:43 AM
jpGraph axis labeling problem Squeezer PHP 2 08-20-03 07:53 AM
php sessions burningr PHP 22 06-12-03 07:07 AM


All times are GMT -5. The time now is 05:02 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.