Ok, to the application, i would need the login page, the database info page, preferbly as an include, a log out page, and the code to be attached at the top of each web page that I wish to be secured. I have attempted said setup, however, when I enter the wrong pass/no pass I get the correct message of "the password is incorrect", but when I attempt to set the session variable so that each page see's I am logged in, the page does not redirect, it stays on index.php. For example, when I enter the known correct password, the page just refreshes, the session variable is not set, nor am I redirected to home.php. FYI, session start has be set at the top of the script, and the synatx for the variable set is correct, I belive there is a problem in the conditional statement. I have spent many hours trying to figure this out, yes I am new to php, but hey everyone has to start somewhere. If anyone would help me, I would owe you Sonic cherry limeade
PHP Simple Login Application Help Requested
Moderator: General Moderators
-
sc1234freak
- Forum Newbie
- Posts: 9
- Joined: Thu Mar 11, 2010 9:24 pm
- Location: Somewhere cold.
PHP Simple Login Application Help Requested
Ok, to cut to the chase. I have a website that is SSL encrypted, and I want all pages to be password protected. I know there are easier methods, however I need a php application. I would like the session to stay active for 14 days, I know this can be completed by changing php.ini, but is there a in script way? I do not need anything fancy such as user accounts/registration, I just need a simple login box that says password, and a submit button. Once the password is entered you get re-directed to "home.php". I also need it so that if you attempt to visit a page without logging in, you are automatically re-directed to the login page, to make things simple, I will be making the login page index.php. I request the password be stored in a MySQL database named "db", with a single table named "clanpassword" with a column name of "clanpass". The database will contain one row which is the password itsself, which will have to be MD5 hashed. FYI I already have said datapase set up, with the password of choice already hashed.
Ok, to the application, i would need the login page, the database info page, preferbly as an include, a log out page, and the code to be attached at the top of each web page that I wish to be secured. I have attempted said setup, however, when I enter the wrong pass/no pass I get the correct message of "the password is incorrect", but when I attempt to set the session variable so that each page see's I am logged in, the page does not redirect, it stays on index.php. For example, when I enter the known correct password, the page just refreshes, the session variable is not set, nor am I redirected to home.php. FYI, session start has be set at the top of the script, and the synatx for the variable set is correct, I belive there is a problem in the conditional statement. I have spent many hours trying to figure this out, yes I am new to php, but hey everyone has to start somewhere. If anyone would help me, I would owe you Sonic cherry limeade
. Thanks in advance for any and all help, I will attach the code below. Thanks again. Please do NOT suggest .htaccess, or anything similar, I need it to work the way I specified. If I was unclear in a section, please let me know. Thanks. Sc1234freak. 
Ok, to the application, i would need the login page, the database info page, preferbly as an include, a log out page, and the code to be attached at the top of each web page that I wish to be secured. I have attempted said setup, however, when I enter the wrong pass/no pass I get the correct message of "the password is incorrect", but when I attempt to set the session variable so that each page see's I am logged in, the page does not redirect, it stays on index.php. For example, when I enter the known correct password, the page just refreshes, the session variable is not set, nor am I redirected to home.php. FYI, session start has be set at the top of the script, and the synatx for the variable set is correct, I belive there is a problem in the conditional statement. I have spent many hours trying to figure this out, yes I am new to php, but hey everyone has to start somewhere. If anyone would help me, I would owe you Sonic cherry limeade
-
sc1234freak
- Forum Newbie
- Posts: 9
- Joined: Thu Mar 11, 2010 9:24 pm
- Location: Somewhere cold.
Re: PHP Simple Login Application Help Requested
First File: db_connect.php
Code: Select all
<?php
//db_connect.php
$con = mysql_connect(localhost,"website","*REMOVED*") or die(mysql_error());
$db = mysql_select_db("db",$con);
function protect($string)
{
$string = mysql_real_escape_string($string);
return $string;
}
?>-
sc1234freak
- Forum Newbie
- Posts: 9
- Joined: Thu Mar 11, 2010 9:24 pm
- Location: Somewhere cold.
Re: PHP Simple Login Application Help Requested
Second File aka The Login Script: index.php
Code: Select all
<?php
session_start();
//Login form (index.php)
include "login/db_connect.php";
if (!$_POST['submit'])
{
?>
<html>
<head><link rel="stylesheet" href="login/style.css"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
</style></head>
<div class="divider">
<strong>Login</strong>
<form method="post" action="index.php">
<div class="formElm">
<label for="password">Clan Password:</label>
<input type="password" name="password" maxlength="16">
</div>
<input type="submit" name="submit" value="Login">
</form>
</div>
<div align="center"></div>
</html>
<?php
}
else
{
$pass = protect($_POST['password']);
$pass = md5($pass); //compare the encrypted password
$clanpasslookup = mysql_query("SELECT clanpass FROM `clanpassword`") or die(mysql_error());
$clanpassvalue = mysql_fetch_array($clanpasslookup);
if ($pass != $clanpassvalue['clanpass'])
{
echo "<script type=\"text/javascript\">
alert(\"The clan password is incorrect!\")
window.location=\"index.php\"</script>";
}
else
{
$_SESSION['auth'] = "jHS590hsHSLQZ8fD801";
echo "<script type=\"text/javascript\">window.location=\"home.php\"</script>";
}
}
?>-
sc1234freak
- Forum Newbie
- Posts: 9
- Joined: Thu Mar 11, 2010 9:24 pm
- Location: Somewhere cold.
Re: PHP Simple Login Application Help Requested
Third File: home.php aka The page I want to link to after login. Yes, I relize there is nothing to be displayed by browser. This is because I removed it.
Code: Select all
<?php
session_start();
if ($_SESSION['auth'] = "jHS590hsHSLQZ8fD801")
{
?>
<html>
<body>
</body>
</html>
<?php
}
else
{
echo "Please login.";
}
?>
-
sc1234freak
- Forum Newbie
- Posts: 9
- Joined: Thu Mar 11, 2010 9:24 pm
- Location: Somewhere cold.
Re: PHP Simple Login Application Help Requested
Forth File: logout.php aka The script I want to use to logout.
Code: Select all
<?php
session_start();
//logout (logout.php)
include "db_connect.php";
if($_SESSION['auth'])
{
session_destroy();
echo "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"You have logged out\");
window.location=\"../index.php\";
</script>";
}
?>-
sc1234freak
- Forum Newbie
- Posts: 9
- Joined: Thu Mar 11, 2010 9:24 pm
- Location: Somewhere cold.
Re: PHP Simple Login Application Help Requested
Fifth File: style.css - I doubt this is inportant, but I included it to be safe then sorry.
Code: Select all
.formElm
{
margin-bottom:5px;
}
.formElm label
{
float:left;
width:120px;
}
div.divider
{
width:450px;
margin:20px auto;
border:4px #000000 double;
padding:10px;
}- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: PHP Simple Login Application Help Requested
I have not looked through all of your code, but this bit caught my eye:
You are re-assigning $_SESSION['auth']. To compare it, you should use "==" as
Code: Select all
<?php
session_start();
if ($_SESSION['auth'] = "jHS590hsHSLQZ8fD801")
{
...
}
?>Code: Select all
if ($_SESSION['auth'] == "jHS590hsHSLQZ8fD801")- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: PHP Simple Login Application Help Requested
Actually, I was kind of bored. Although this is an extremely weak login script, here you go. Note that it is untested, so you may need to debug it.
Code: Select all
<?php
/* Login Form (index.php) */
# Start Session
session_start();
# Includes
// Try to use an absolute path starting from the root dir when possible
// ex: /var/www/login_project/login/db_connect.php
// Use include_once();
include_once("login/db_connect.php");
# Handle Form Post
if($_POST['submit']) {
# Fetch POST vars
// md5 is not cryptographically suitable. You should use atleast sha256
$pass = (isset($_POST['password']) && !empty($_POST['password'])) ? hash('sha512', $_POST['password']) : '';
# Sanity Check
if(empty($pass)) {
# Redirect to login page
header('location:http://example.org/index.php?error=' . urlencode("Incorrect Password."));
exit();
}
# Fetch Password store from the database
// Do not display mysql_error() in a production environment
$clanpasslookup = mysql_query("SELECT `clanpass` FROM `clanpassword` LIMIT 1;");
# Verify Query was successful and atleast 1 row returned in result set
if(!$clanpasslookup || mysql_numrows($clanpasslookup) == 0) {
# Redirect to login page
header('location:http://example.org/index.php?error=' . urlencode("Incorrect Password."));
exit();
} else {
$clanpassvalue = mysql_fetch_array($clanpasslookup);
}
if($pass != $clanpassvalue['clanpass']) {
/* Passwords do not match */
# Redirect to login page
header('location:http://example.org/index.php?error=' . urlencode("Incorrect Password."));
exit();
} else {
/* Passwords match*/
# Regenerate Session Id
session_regenerate_id(1);
# Set Authentication Token
$_SESSION['auth'] = "jHS590hsHSLQZ8fD801";
# Redirect to user home
header('location:http://example.org/home.php');
exit();
}
} else {
?>
<html>
<head>
<link rel="stylesheet" href="login/style.css"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css"></style>
</head>
<body>
<div class="divider">
<strong>Login</strong>
<?php
# If there was an error, fetch error text
$error = (isset($_GET['error'])) ? $_GET['error'] : '';
# If there was an error, display error text
if(!empty($error))
print $error;
?>
<form method="post" action="index.php">
<div class="formElm">
<label for="password">Clan Password:</label>
<input type="password" name="password" maxlength="16">
</div>
<input type="submit" name="submit" value="Login">
</form>
</div>
<div align="center"></div>
</body>
</html>
<?php
}
?>Code: Select all
<?php
/* Home (home.php) */
# Start Session
session_start();
# Check Authorization Token
// (Best Practice says to fail first when possible)
if(!isset($_SESSION['auth']) || $_SESSION['auth'] != "jHS590hsHSLQZ8fD801") {
# Redirect to login page
header('location:http://example.org/index.php');
exit();
} else {
?>
<html>
<body>
We Are Home (Logged In)
</body>
</html>
<?php
}
?>Code: Select all
<?php
/* logout (logout.php) */
# Start Session
session_start();
# Clear Authorized Flag
if(isset($_SESSION['auth']))
unset($_SESSION['auth']);
# Regenerate Session Id
session_regenerate_id(1);
# Redirect to login page
header('location:http://example.org/index.php');
exit();
?>-
sc1234freak
- Forum Newbie
- Posts: 9
- Joined: Thu Mar 11, 2010 9:24 pm
- Location: Somewhere cold.
Re: PHP Simple Login Application Help Requested
THANK YOU so much for the help, you saved my life. I went ahead and tested the script on my local computer. I noticed however that when the correct password is entered, and you hit enter to submit, the webpage refreshes. However if you type the same password, it works, any ideas?. Please note, I used relative links for testing purposes on a local computer. Ill go ahead and post my login page. Thanks again. Sc1234freak.
EDIT: Is there a way to re-direct rather then then the header:location way. I am getting errors like "Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\publish\login.php:1) in C:\xampp\htdocs\publish\login.php on line 4 & Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\publish\index.php:1) in C:\xampp\htdocs\publish\index.php on line 10" The script worked in the limited mode, but when I added my HTML I'm getting these errors. I belive I need a better way to re-direct then header:location, but Im no expert. :p Thanks again. FYI: I also changed it so index.php is my legit home page, and login.php is the login system.
Code: Select all
<?php
/* Code to secure pages */
# Start Session
session_start();
# Check Authorization Token
// (Best Practice says to fail first when possible)
if(!isset($_SESSION['auth']) || $_SESSION['auth'] != "jHS590hsHSLQZ8fD801") {
# Redirect to login page
header('location:login.php');
exit();
} else {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Serif WebPlus X4 (12.0.1.022)">
<title>Home</title>
<meta name="keywords" content="Sc1234freak,Sc1234freak Clan,Sc1234freak's Clan Website,The Legends,The Legends Clan">
<meta name="description" content="Sc1234freak's Clan Website">
<meta name="author" content="Sc1234freak">
<meta name="copyright" content="© Sc1234freak - 2010">
<meta http-equiv="Content-Language" content="en-us">
<meta name="robots" content="noindex,nofollow">
<script type="text/javascript" src="wpscripts/jsNavBarFuncs.js"></script>
<script type="text/javascript" src="wpscripts/global_navtree.js"></script>
<script type="text/javascript" src="wpscripts/wp_navbar_flash.js"></script>
<style type="text/css">
<!--
body {margin: 0px; padding: 0px;}
a:link {color: #0000ff;}
a:visited {color: #000080;}
a:hover {color: #000080;}
a:active {color: #0000ff;}
.Body-P
{
margin:0.0px 0.0px 12.0px 0.0px; text-align:left; font-weight:400;
}
.Artistic-Body-P
{
margin:0.0px 0.0px 0.0px 0.0px; text-align:right; font-weight:400;
}
.Body-P0
{
margin:0.0px 0.0px 12.0px 0.0px; text-align:center; font-weight:400;
}
.Body-C
{
font-family:"Verdana", sans-serif; font-weight:700; font-size:11.0px;
line-height:1.18em;
}
.Artistic-Body-C
{
font-family:"Verdana", sans-serif; font-size:13.0px;
line-height:1.23em;
}
.Body-C0
{
font-family:"Verdana", sans-serif; font-weight:700; font-size:16.0px;
line-height:1.13em;
}
.Body-C1
{
font-family:"Verdana", sans-serif; font-size:16.0px;
line-height:1.13em;
}
.Body-C2
{
font-family:"Verdana", sans-serif; font-size:16.0px;
line-height:1.13em; color:#612420;
}
-->
</style>
<script type="text/javascript" src="wpscripts/jspngfix.js"></script>
<script type="text/javascript"><!--
var blankSrc = "wpscripts/blank.gif";
--></script>
</head>
<body text="#000000" style="background-color:#9c5b2c; text-align:center; height:800px;">
<div style="background-color:transparent;text-align:left;margin-left:auto;margin-right:auto;position:relative;width:1024px;height:800px;">
<div style="position:absolute; left:0px; top:0px; width:1024px; height:771px;">
<img src="wpimages/wp35e59b77.png" width="1024" height="771" border="0" id="qs_2" name="qs_2" title="" alt="" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:0px; top:772px; width:1024px; height:28px;">
<img src="wpimages/wpc20ec91e.png" width="1024" height="28" border="0" id="qs_5" name="qs_5" title="" alt="" onload="OnLoadPngFix()"></div>
<div id="nav_77" style="position:absolute; left:0px; top:74px; width:922px; height:87px;">
<script type="text/javascript"><!--
try {
var navtree_nav_77 = WpNavBar.getNavTreeTopLevel( global_navtree, {m_sThisPageUrl:'index.php',
m_sNavBarTarget:'_self',
m_bIncludeAnchors:false,
m_bIncludeChildren:false,
m_bHideCurrent:false} );
if( !navtree_nav_77 ) throw WpNavBar.getErrorObj( 'Link tree could not be read' );
var nav_77 = new wp_navbar_flash("nav_77", navtree_nav_77, {'ExportNoScript':false,m_iWidth:922,
m_iHeight:87}, {'sFlashFile':'wpscripts/Designer_08_DD.swf','MenuButtonItem1Col':'944b22','MenuButtonItem2Col':'a96e4a','MenuButtonItem3Col':'ff00ff','ButtonCaps':false,'FontStyle':'Tahoma','FontSize':'20','FontColour':'#944b22','FontAlign':1,'endColor':'#ffffff','ButtonMargin':2,'ButtonSpace':20,'MenuDivider':false,'Margin':0,'MenuAlignMent':1,'MenuButtonStretch':true,'StretchButtons':false,'SubMenuMargin':10,'SubMenuButtonItem1Col':'944b22','SubMenuButtonItem2Col':'d1dde2','SubFontStyle':'Tahoma','SubFontSize':12,'SubFontColour':'#9c5b2c','SubTextOver':'#612420','SubButtonStretch':true,'VerticalMenus':false,'DropdownMenus':true,'differencePos':0,'ParticleColour':'#ff8000','NumberParticles':30,'Direction':0,'FixButtons':false,'SubInline':false,'SpeakFontStyle':'Tahoma','SpeakFontSize':'12','SpeakFontColour':'#cfa78c','SpeakFontAlign':1,'Speak':false,'ButtonScale':120});
} catch(e){
document.write( 'There was an error generating the navbar:<br>' + e.message );
}
--></script>
</div>
<div id="txt_1" style="position:absolute; left:0px; top:785px; width:316px; height:15px;-moz-box-sizing:border-box;box-sizing:border-box; overflow:hidden;">
<p class="Body-P"><span class="Body-C">Donors: Sc1234freak ($ 99.93), Erin ($ 15.00)</span></p>
</div>
<div style="position:absolute; left:743px; top:784px; width:270px; height:16px;">
<div class="Artistic-Body-P">
<span class="Artistic-Body-C"><a href="logout.php">Logout</a> | <a href="contact.php">Contact Us</a> | <a href="donate.php">Donate</a></span></div>
</div>
<div style="position:absolute; left:0px; top:0px; width:1024px; height:64px;">
<img src="wpimages/wp8a8047ca_05.jpg" width="1024" height="64" border="0" id="pic_5" name="pic_5" title="" alt=""></div>
<div style="position:absolute; left:572px; top:186px; width:190px; height:23px;">
<img src="wpimages/wped2a4168.png" width="190" height="23" border="0" id="art_1" name="art_1" title="" alt="Est. December 2007" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:771px; top:484px; width:228px; height:263px;">
<img src="wpimages/wp5730c55d.png" width="228" height="263" border="0" id="qs_2" name="qs_2" title="" alt="" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:125px; top:139px; width:280px; height:122px;">
<img src="wpimages/wpcfee9bb5.png" width="280" height="122" border="0" id="qs_1" name="qs_1" title="" alt="" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:278px; top:258px; width:469px; height:285px;">
<img src="wpimages/wp627385f4.png" width="469" height="285" border="0" id="qs_2" name="qs_2" title="" alt="" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:13px; top:136px; width:175px; height:174px;">
<img src="wpimages/wpb9ee888b.png" width="175" height="174" border="0" id="pic_6" name="pic_6" title="" alt="" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:837px; top:134px; width:175px; height:174px;">
<img src="wpimages/wpd5580449.png" width="175" height="174" border="0" id="pic_7" name="pic_7" title="" alt="" onload="OnLoadPngFix()"></div>
<div style="position:absolute; left:129px; top:153px; width:277px; height:99px;">
<img src="wpimages/wpb6aca00a.png" width="277" height="99" border="0" id="art_2" name="art_2" title="" alt="The only clan that everyone wants to be in!" onload="OnLoadPngFix()"></div>
<div id="txt_1" style="position:absolute; left:791px; top:501px; width:185px; height:221px;-moz-box-sizing:border-box;box-sizing:border-box; overflow:hidden;">
<p class="Body-P0"><span class="Body-C0">Welcome to The Legends Clan Website!</span></p>
<p class="Body-P0"><span class="Body-C0"> </span></p>
<p class="Body-P0"><span class="Body-C0">We have 70+ active members, and have been running non-<wbr>stop for two years. </span></p>
<p class="Body-P0"><span class="Body-C0">Welcome to the adventure</span><span class="Body-C1">!</span></p>
<p class="Body-P0"><span class="Body-C2"> </span></p>
</div>
<div style="position:absolute; left:287px; top:268px; width:451px; height:263px;">
<img src="wpimages/wpce6352de_05.jpg" width="451" height="263" border="0" id="pic_1" name="pic_1" title="Clan Photo" alt="Clan Photo"></div>
<div style="position:absolute; left:35px; top:511px; width:129px; height:197px;">
<img src="wpimages/wp3a9e32be.png" width="129" height="197" border="0" id="pic_4" name="pic_4" title="" alt="" onload="OnLoadPngFix()"></div>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-15096683-1");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>
<?php
}
?>Code: Select all
<?php
/* Login Form (login.php) */
# Start Session
session_start();
# Includes
// Try to use an absolute path starting from the root dir when possible
// ex: /var/www/login_project/login/db_connect.php
// Use include_once();
include_once("secure/db_connect.php");
# Handle Form Post
if($_POST['submit']) {
# Fetch POST vars
// md5 is not cryptographically suitable. You should use atleast sha256
$pass = (isset($_POST['password']) && !empty($_POST['password'])) ? hash('sha512', $_POST['password']) : '';
# Sanity Check
if(empty($pass)) {
# Redirect to login page
header('location:login.php?error=' . urlencode("Incorrect Password."));
exit();
}
# Fetch Password store from the database
// Do not display mysql_error() in a production environment
$clanpasslookup = mysql_query("SELECT `clanpass` FROM `clanpassword` LIMIT 1;");
# Verify Query was successful and atleast 1 row returned in result set
if(!$clanpasslookup || mysql_numrows($clanpasslookup) == 0) {
# Redirect to login page
header('location:login.php?error=' . urlencode("Incorrect Password."));
exit();
} else {
$clanpassvalue = mysql_fetch_array($clanpasslookup);
}
if($pass != $clanpassvalue['clanpass']) {
/* Passwords do not match */
# Redirect to login page
header('location:login.php?error=' . urlencode("Incorrect Password."));
exit();
} else {
/* Passwords match*/
# Regenerate Session Id
session_regenerate_id(1);
# Set Authentication Token
$_SESSION['auth'] = "jHS590hsHSLQZ8fD801";
# Redirect to user home
header('location:index.php');
exit();
}
} else {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Serif WebPlus X4">
<title>Login</title>
<meta name="keywords" content="Sc1234freak,Sc1234freak Clan,Sc1234freak's Clan Website,The Legends,The Legends Clan">
<meta name="description" content="Sc1234freak's Clan Website">
<meta name="author" content="Sc1234freak">
<meta name="copyright" content="© Sc1234freak - 2010">
<meta http-equiv="Content-Language" content="en-us">
<meta name="robots" content="index,nofollow">
<script type="text/javascript">
<!--
function validate_form_1( form )
{
if( ltrim(rtrim(form.elements['edit_2'].value,' '),' ')=="" ) { alert("Incorrect Password."); form.elements['edit_2'].focus(); return false; }
return true;
}
-->
</script>
<style type="text/css">
<!--
body {margin: 0px; padding: 0px;}
a:link {color: #0000ff;}
a:visited {color: #000080;}
a:hover {color: #000080;}
a:active {color: #0000ff;}
.Body-P
{
margin:0.0px 0.0px 12.0px 0.0px; text-align:center; font-weight:400;
}
.Body-P0
{
margin:0.0px 0.0px 12.0px 0.0px; text-align:left; font-weight:400;
}
.Body-C
{
font-family:"Dragline BTN Dm", sans-serif; font-weight:700;
font-size:48.0px; line-height:1.23em;
}
.Body-C0
{
font-family:"Verdana", sans-serif; font-size:16.0px;
line-height:1.13em;
}
.Body-C1
{
font-family:"Verdana", sans-serif; font-weight:700; font-size:16.0px;
line-height:1.13em;
}
.Body-C2
{
font-family:"Verdana", sans-serif; font-weight:700; font-size:16.0px;
line-height:1.13em; text-decoration: underline;
}
-->
</style>
<script type="text/javascript" src="wpscripts/jspngfix.js"></script>
<script type="text/javascript"><!--
var blankSrc = "wpscripts/blank.gif";
--></script>
<script type="text/javascript" src="wpscripts/jsValidation.js"></script>
</head>
<body text="#000000" style="background-color:#9c5b2c; text-align:center; height:600px;">
<div style="background-color:transparent;text-align:left;margin-left:auto;margin-right:auto;position:relative;width:600px;height:600px;">
<div style="position:absolute; left:9px; top:8px; width:584px; height:583px;">
<img src="wpimages/wp07eb701b.png" width="584" height="583" border="0" id="qs_12" name="qs_12" title="" alt="" onload="OnLoadPngFix()"></div>
<div id="txt_1" style="position:absolute; left:38px; top:33px; width:525px; height:75px;-moz-box-sizing:border-box;box-sizing:border-box; overflow:hidden;">
<p class="Body-P"><span class="Body-C">The Legend’s Clan</span></p>
</div>
<div style="position:absolute; left:53px; top:136px; width:489px; height:373px;">
<img src="wpimages/wp4dc472d9.png" width="489" height="373" border="0" id="pic_1" name="pic_1" title="" alt="" onload="OnLoadPngFix()"></div>
<form method="post" action="login.php">
<form id="password" onSubmit="return validate_form_1(this)" action="" method="post" target="_self" enctype="application/x-www-form-urlencoded" style="margin:0px;">
<div style="position:absolute; left:234px; top:349px; width:155px; height:22px; text-align:left;">
<input type="password" id="edit_2" name="edit_2" size="21" style="width:155px;" maxlength="16" value="">
</div>
<div style="position:absolute; left:260px; top:408px; width:81px; height:22px; text-align:left;">
<input type="submit" id="butn_1" value="Login">
</div>
<div id="txt_1" style="position:absolute; left:102px; top:355px; width:126px; height:27px;-moz-box-sizing:border-box;box-sizing:border-box; overflow:hidden;">
<p class="Body-P0"><span class="Body-C0">Clan Password:</span></p>
</div>
</form>
<div style="position:absolute; left:366px; top:454px; width:206px; height:129px;">
<img src="wpimages/wp910fe8a9.png" width="206" height="129" border="0" id="qs_2" name="qs_2" title="" alt="" onload="OnLoadPngFix()"></div>
<div id="txt_2" style="position:absolute; left:374px; top:458px; width:192px; height:115px;-moz-box-sizing:border-box;box-sizing:border-box; overflow:hidden;">
<p class="Body-P"><span class="Body-C1">Please Note:</span><span class="Body-C0"> Pressing the Enter button to submit the password currently does </span><span class="Body-C2">NOT</span><span class="Body-C0">
work. It is being looked into.</span></p>
</div>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-15096683-1");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>
<?php
# If there was an error, fetch error text
$error = (isset($_GET['error'])) ? $_GET['error'] : '';
# If there was an error, display error text
if(!empty($error))
print $error;
}
?>-
sc1234freak
- Forum Newbie
- Posts: 9
- Joined: Thu Mar 11, 2010 9:24 pm
- Location: Somewhere cold.
Re: PHP Simple Login Application Help Requested
Is this due to the fact I decided to flip the login file to login.php and make the home page index.php?
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\publish\index.php:1) in C:\xampp\htdocs\publish\index.php on line 4
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\publish\index.php:1) in C:\xampp\htdocs\publish\index.php on line 4
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\publish\index.php:1) in C:\xampp\htdocs\publish\index.php on line 4
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\publish\index.php:1) in C:\xampp\htdocs\publish\index.php on line 4
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: PHP Simple Login Application Help Requested
You have to send all the headers you want to send, before you send any output. This is the reason you are receiving the error message.
At the beginning of your index.php file try putting this bit of code:
At the beginning of your index.php file try putting this bit of code:
Code: Select all
<?php
#Begin Output Buffering
ob_start();
?>-
sc1234freak
- Forum Newbie
- Posts: 9
- Joined: Thu Mar 11, 2010 9:24 pm
- Location: Somewhere cold.
Re: PHP Simple Login Application Help Requested
No, this did not work. Nice suggestion though. I see the problem I think, so is there a way to redirect with php rather then use the header(location:) way? For testing purposes I set the login back to index and I still got the following errors.
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\publish\index.php:1) in C:\xampp\htdocs\publish\index.php on line 6
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\publish\index.php:1) in C:\xampp\htdocs\publish\index.php on line 6
This is the absolute top that I have for my index.php file. Any ideas, once again, thanks for the help.
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\publish\index.php:1) in C:\xampp\htdocs\publish\index.php on line 6
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\publish\index.php:1) in C:\xampp\htdocs\publish\index.php on line 6
This is the absolute top that I have for my index.php file. Any ideas, once again, thanks for the help.
Code: Select all
<?php
/* Login Form (index.php) */
#Begin Output Buffering
ob_start();
# Start Session
session_start();
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: PHP Simple Login Application Help Requested
The redirect using header(location:) is not the problem. In the error message, it says: "output started at C:\xampp\htdocs\publish\index.php:1".
It also says: "Cannot send session cookie - headers already sent (...) in C:\xampp\htdocs\publish\index.php on line 6".
When you call session_start() in line 6, your script is trying to send http headers but it can't because your script has already begun output at line 1. Something as small as a space or new line in line 1 will be considered output.
It also says: "Cannot send session cookie - headers already sent (...) in C:\xampp\htdocs\publish\index.php on line 6".
When you call session_start() in line 6, your script is trying to send http headers but it can't because your script has already begun output at line 1. Something as small as a space or new line in line 1 will be considered output.