harmclan Posted April 15, 2008 Share Posted April 15, 2008 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 https://forums.phpfreaks.com/topic/101268-need-help-with-login-script/ Share on other sites More sharing options...
KevinM1 Posted April 15, 2008 Share Posted April 15, 2008 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 https://forums.phpfreaks.com/topic/101268-need-help-with-login-script/#findComment-517990 Share on other sites More sharing options...
harmclan Posted April 15, 2008 Author Share Posted April 15, 2008 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 https://forums.phpfreaks.com/topic/101268-need-help-with-login-script/#findComment-518001 Share on other sites More sharing options...
unidox Posted April 15, 2008 Share Posted April 15, 2008 Use sessions, cookies can be manipulated. Link to comment https://forums.phpfreaks.com/topic/101268-need-help-with-login-script/#findComment-518002 Share on other sites More sharing options...
harmclan Posted April 15, 2008 Author Share Posted April 15, 2008 Are there any good tutorials i could look off of? I'll start reading up about it. Thanks for the response, sort of a noobie when it comes to scripting Link to comment https://forums.phpfreaks.com/topic/101268-need-help-with-login-script/#findComment-518019 Share on other sites More sharing options...
unidox Posted April 15, 2008 Share Posted April 15, 2008 Yea, check your pm. Just made it. Link to comment https://forums.phpfreaks.com/topic/101268-need-help-with-login-script/#findComment-518043 Share on other sites More sharing options...
PRodgers4284 Posted April 15, 2008 Share Posted April 15, 2008 Are there any good tutorials i could look off of? I'll start reading up about it. Thanks for the response, sort of a noobie when it comes to scripting do a search for evolt login script in google, the evolt site provides a good login script Link to comment https://forums.phpfreaks.com/topic/101268-need-help-with-login-script/#findComment-518045 Share on other sites More sharing options...
stuart7398 Posted April 15, 2008 Share Posted April 15, 2008 http://phpsense.com/php/php-login-script.html Link to comment https://forums.phpfreaks.com/topic/101268-need-help-with-login-script/#findComment-518074 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.