Jump to content

need help with login script


harmclan

Recommended Posts

Ok, I've been working on attempting to add a login script to the top of my header (http://ustropics.ulmb.com/header.php). I'm using a div to position the login.php file, and everything is showing and seems to be functioning. The problem is, when I login and I go to the members page (/members.php) it shows me as logged in (I'm using cookies to remember my session). However, when i return to my header file it shows me as logged out (yet I'm still logged in members.php and if i remotely access login.php it also shows me as logged in). Am I doing something wrong with sessions or should I approach this from a different angle?

 

Here's the sources -

 

http://ustropics.ulmb.com/header.php (just a banner with some unlinked buttons and the div with the login.php)

http://ustropics.ulmb.com/login.php (Login script. Everything is functioning stand alone)

http://ustropics.ulmb.com/members.php (Also shows me as logged in)

Link to comment
Share on other sites

Ok, I've been working on attempting to add a login script to the top of my header (http://ustropics.ulmb.com/header.php). I'm using a div to position the login.php file, and everything is showing and seems to be functioning. The problem is, when I login and I go to the members page (/members.php) it shows me as logged in (I'm using cookies to remember my session). However, when i return to my header file it shows me as logged out (yet I'm still logged in members.php and if i remotely access login.php it also shows me as logged in). Am I doing something wrong with sessions or should I approach this from a different angle?

 

Here's the sources -

 

http://ustropics.ulmb.com/header.php (just a banner with some unlinked buttons and the div with the login.php)

http://ustropics.ulmb.com/login.php (Login script. Everything is functioning stand alone)

http://ustropics.ulmb.com/members.php (Also shows me as logged in)

 

You should post your code directly rather than links.  PHP doesn't show up when trying to view source code from a site.

Link to comment
Share on other sites

Done. Sorry about that. I have mozilla's Web Developer addon and didn't realize this.

 

header.php

<?php
session_start();
?>

<html>
<head>
<title>header</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="styles/header.css" />
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (header.psd) -->
<table id="Table_01" width="800" height="170" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td rowspan="3">
		<img src="images/header_01.gif" width="27" height="170" alt=""></td>
	<td rowspan="2">
		<img src="images/header_02.gif" width="26" height="118" alt=""></td>
	<td background="images/header_03.gif" width="721" height="88" colspan="6"><div id="login" style="position:relative;width: 721px;height: 88px;align: right;"> <? include('login.php'); ?></div>

	</td>
	<td rowspan="3">
		<img src="images/header_04.gif" width="26" height="170" alt=""></td>
</tr>
<tr>
	<td rowspan="2">
		<img src="images/header_05.gif" width="138" height="82" alt=""></td>
	<td rowspan="2">
		<img src="images/header_06.gif" width="135" height="82" alt=""></td>
	<td rowspan="2">
		<img src="images/header_07.gif" width="135" height="82" alt=""></td>
	<td rowspan="2">
		<img src="images/header_08.gif" width="135" height="82" alt=""></td>
	<td rowspan="2">
		<img src="images/header_09.gif" width="153" height="82" alt=""></td>
	<td>
		<img src="images/header_10.gif" width="25" height="30" alt=""></td>
</tr>
<tr>
	<td>
		<img src="images/header_11.gif" width="26" height="52" alt=""></td>
	<td>
		<img src="images/header_12.gif" width="25" height="52" alt=""></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>

 

login.php

<?php

include_once "includes/functions.php"; //Functions file
include "inlcudes/session.php";

connect(); //Connect to DB from array in functions.php

if(isset($_COOKIE['ID_my_site']))

{
$username	= $_COOKIE['ID_my_site'];
$password	= $_COOKIE['Key_my_site'];
$check		= mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
	if ($password != $info['password'])
	{
	}else{
		echo "testin2";
	}
}
}

if (isset($_POST['submit'])) {
if(!$_POST['username'] | !$_POST['password']) {
	die('You did not fill in a required field!');
}

if (!get_magic_quotes_gpc()) {
	$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or
die(mysql_error());

$check2 = mysql_num_rows($check);
if ($check2 == 0) {
	die('That user does not exist in our database. <a href="register.php">Click here to register</a>');
}
while($info = mysql_fetch_array( $check ))
{
	$_POST['password'] = stripslashes($_POST['password']);
	$info['password'] =
	stripslashes($info['password']);
	$_POST['password'] = md5($_POST['password']);

	if ($_POST['password'] != $info['password']) {
		die('Incorrect password, please try again.');
	}else {
		$_POST['username'] =
		stripslashes($_POST['username']);
		$hour = time() + 3600;
		setcookie(ID_my_site, $_POST['username'], $hour);
		setcookie(Key_my_site, $_POST['password'], $hour);

		//header("Location: members.php");
		echo "testing";
	}
}
}else{
?>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td><font color="white">Username:</font></td><td>
<input type="text" name="username" maxlength="40" size="10">
</td></tr>
<tr><td><font color="white">Password:</font></td><td>
<input type="password" name="password" maxlength="50" size="10">
</td>
<td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>

<?php
}

?>

 

members.php

<?php
include_once "includes/functions.php"; //Functions file

connect(); //Array from functions.php

if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$password = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
	if ($password != $info['password']) {
		header("Location: login.php");

	}else {
		echo "Admin Area<p>";
		echo "Your Content<p>";
		echo "<a href=logout.php>Logout</a>";
	}
}

}else{
echo "access restricted! Please <a href=\"login.php\">login here</a>.\n";
}

?>

 

 

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.