Jump to content

Login Script


dennismonsewicz

Recommended Posts

Ok...

 

I have this login script:

 


<?php
//page title: checklogin.php
ob_start();
include "includes/db_login.php";

	// username and password sent from signup form
	$username = $_POST['username'];
	$password = $_POST['password'];
	$userid = $_POST['userid'];

	$sql="SELECT * FROM users WHERE username='$username' and password='$password' and userid='$userid'";
	$result=mysql_query($sql) or die(mysql_error());


	// Mysql_num_row is counting table row
	$count=mysql_num_rows($result);

	// If result matched $username and $password, table row must be 1 row

	if($count==1){
	// Register $username, $password and redirect to file "login_success.php"
	session_register("username");
	session_register("password");
	header("location:../index.php");
	}
	else {
	include "includes/header.php";
	echo "<p>Wrong Username or Password</p>";
	include "includes/footer.php";
	}

ob_end_flush();

?>

 

The information being pulled from this script is on this page:

 

<?php include "includes/header.php"; 
//page title: login_index.php
?>
        
    <p>To login, please fill out the form below with your given username and password</p>
    
    <div id="loginform">
    
    	<form name="form1" method="post" action="checklogin.php">
        	<table border="0" cellpadding="0" cellspacing="0" align="center">
            	<tr>
                    <td>Username: </td>
                    <td><input name="username" type="text" id="username" /></td>
                </tr>
                <tr>
                  	 <td>Password: </td>
                     <td><input name="password" type="password" id="password" /></td>
                 </tr>
                 <tr>
                 	<td colspan="2"><input type="image" src="../images/login.gif" class="submit" alt="Submit Changes" value="Login" /></td>
                 </tr>
             </table>
        </form>
        
    </div>
    
<?php include "includes/footer.php"; ?>

 

Now here is my question:

 

I want to be able to transfer the username to the my header.php file which is an include for the main site. Right now I have a logout button. Well in parenthesis right beside the logout button I want to put the username that is logged in. How do I pass the username and rowid variable from the checklogin.php to header.php?

 

header.php looks like this:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Intranet</title>
<link href="/styles.css" rel="stylesheet" type="text/css" />
</head>

<body>

<?PHP session_start();

if(!session_is_registered(username)){
header("location:login/index.php")
}

?>

<a name="top"></a>

<div id="header">
    	<div id="logout" style="float: right; margin-right:50px; margin-top: 20px;"><a href="http://intranet.healthresources.net/login/logout.php">Logout? <?php echo "(" .  $username . ")" ?></a></div>
    	 ?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.