Hello all,
I wrote this log in script and everything seems to be good but it throws me this:
Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home2/*****/public_html/dbconnect.php:1) in /home2/chicagt7/public_html/functions.php on line 2
here is the loginscript.php:
[code=php]<?php
require_once(‘dbconnect.php’);
include(‘functions.php’);
if(isset($_POST[‘Login’]))
{
if($_POST[‘usern’]!=” && $_POST[‘passw’]!=”)
{
//Use the input username and password and check against ‘users’ table
$query = mysql_query(‘SELECT ID, uname, Active FROM `users` WHERE uname = “‘.mysql_real_escape_string($_POST[‘usern’]).'” AND pass = “‘.mysql_real_escape_string(md5($_POST[‘passw’])).'”‘);
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
if($row[‘Active’] == 1)
{
$_SESSION[‘user_id’] = $row[‘ID’];
$_SESSION[‘logged_in’] = TRUE;
header(“Location: members.php”);
redirect (“index2.php”);
}
else {
$error = ‘Your membership was not activated. Please open the email that we sent and click on the activation link’;
}
}
else {
$error = ‘Login failed !’;
}
}
else {
$error = ‘Please user both your username and password to access your account’;
}
}
?>
<?php if(isset($error)){ echo $error;}?>
<form action=”<?=$_SERVER[‘PHP_SELF’]?>” method=”post”>
<input type=”text” id=”username” name=”username” size=”32″ value=”” />
<input type=”password” id=”password” name=”password” size=”32″ value=”” />
<input type=”submit” name=”Login” value=”Login” />
</form>
and here is the functions.php:
[code=php]<?
session_start();
//connect to the database
require (“dbconnect.php”);
//send the user somewhere else
function redirect($url)
{
ob_start();
header(‘location: ‘ . $url);
ob_end_flush();
}
//rearranges a date
function rearrangedate($date)
{
$date1 = explode(‘-‘, $date);
$newdate = $date1[1] . “-” . $date1[2] . “-” . $date1[0];
echo $newdate;
}
//rearranges a date and time
function rearrangedatetime($datetime)
{
$datetime1 = explode(” “, $datetime);
$date1 = explode(‘-‘, $datetime1[0]);
$newdatetime = $date1[1] . “-” . $date1[2] . “-” . $date1[0] . ” at ” . $datetime1[1];
echo $newdatetime;
}
?>
any help please!
[code=php]<?php
//opens a connection to the MYSQUL
$dbc = mysql_connect('localhost', '*******', '******');
if (!dbc)
{
die('Server is off line try back later :' . mysql_error());
}
//selects the MYSQL database
$db_selected = mysql_select_db("******", $dbc);
if (!$db_selected)
{
die ("cant connect :" . mysql_error());
}
?>[/code]
[code=php]<?php
include('functions.php');
require_once('dbconnect.php');
if(isset($_POST['Login']))
{
if($_POST['usern']!='' && $_POST['passw']!='')
{
//Use the input username and password and check against 'users' table
$query = mysql_query('SELECT ID, uname, Active FROM users
WHERE uname = "'.mysql_real_escape_string($_POST['usern']).'" AND pass = "'.mysql_real_escape_string(md5($_POST['passw'])).'"');
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
if($row['Active'] == 1)
{
$_SESSION['user_id'] = $row['ID'];
$_SESSION['logged_in'] = TRUE;
header("Location: members.php");
redirect ("index2.php");
}
else {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
}
}
else {
$error = 'Login failed !';
}
}
else {
$error = 'Please use both your username and password to access your account';
}
}
?>
<?php if(isset($error)){ echo $error;}?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" id="username" name="username" size="32" value="" />
<input type="password" id="password" name="password" size="32" value="" />
<input type="submit" name="Login" value="Login" />
</form>[/code]
[code=php]<?php
session_start();
//connect to the database
require ("dbconnect.php");
//send the user somewhere else
function redirect($url)
{
ob_start();
header('location: ' . $url);
ob_end_flush();
}
//rearranges a date
function rearrangedate($date)
{
$date1 = explode('-', $date);
$newdate = $date1[1] . "-" . $date1[2] . "-" . $date1[0];
echo $newdate;
}
//rearranges a date and time
function rearrangedatetime($datetime)
{
$datetime1 = explode(" ", $datetime);
$date1 = explode('-', $datetime1[0]);
$newdatetime = $date1[1] . "-" . $date1[2] . "-" . $date1[0] . " at " . $datetime1[1];
echo $newdatetime;
}
?>[/code]
Do you have errors set to E_ALL? Maybe there is a warning or notice that is causing the error? Do you have a publicly available version I can access to test?[/QUOTE]
Something is being printed out before the Header (which is the same error that caused the session_start() from working). Look for any spacesnew lines in your files that are outside of <?php ?>.[/QUOTE]
header("Location: members.php");
redirect ("index2.php");
[/quote]
Well, got:
"Please use both your username and password to access your account"
While trying to connect via loginscript.php (login.php just sent me there without any messages). Which the input fields are username and password and the posts are usern and passw. However, on login.php, $_POST['Login'] isn't being set anywhere so it's not pushing the usernpassw to the loginscript.[/QUOTE]
[code=php]<?php
include('functions.php');
require_once('dbconnect.php');
if(isset($_POST['Login']))
{
if($_POST['usern']!='' && $_POST['passw']!='')
{
//Use the input username and password and check against 'users' table
$query = mysql_query('SELECT ID, uname, Active FROM users
WHERE uname = "'.mysql_real_escape_string($_POST['usern']).'" AND pass = "'.mysql_real_escape_string(md5($_POST['passw'])).'"');
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
if($row['Active'] == 1)
{
$_SESSION['user_id'] = $row['ID'];
$_SESSION['logged_in'] = TRUE;
redirect ('index2.php');
}
else {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
}
}
else {
$error = 'Login failed !';
}
}
else {
$error = 'Please use both your username and password to access your account';
}
}
?>
<?php if(isset($error)){ echo $error;}?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" id="username" name="username" size="32" value="" />
<input type="password" id="password" name="password" size="32" value="" />
<input type="submit" name="Login" value="Login" />
</form>[/code]
[code=php]<?php
session_start();
//connect to the database
require ("dbconnect.php");
//send the user somewhere else
function redirect($url)
{
ob_start();
header('location: ' . index2.php);
ob_end_flush();
}
//rearranges a date
function rearrangedate($date)
{
$date1 = explode('-', $date);
$newdate = $date1[1] . "-" . $date1[2] . "-" . $date1[0];
echo $newdate;
}
//rearranges a date and time
function rearrangedatetime($datetime)
{
$datetime1 = explode(" ", $datetime);
$date1 = explode('-', $datetime1[0]);
$newdatetime = $date1[1] . "-" . $date1[2] . "-" . $date1[0] . " at " . $datetime1[1];
echo $newdatetime;
}
?>[/code]
We found out what was causing your problem before...why did it come back? Also you still haven't either renamed $_POST['usern'] and $_POST['passw'] to $_POST['username'] and $_POST['password'] or changed the name/ids of the input fields from username and password to usern and passw...[/QUOTE]
[code=php]
function redirect($url) {
if (!headers_sent()) {
//If headers not sent yet... then do php redirect
header('Location: '.$url); exit;
} else {
//If headers are sent... do javascript redirect... if javascript disabled, do html redirect.
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>'; exit;
}
}
[/code]
[code=php]
$url = "/redirect.php"; // This is the variable with the URL
redirect($url); // This is using the variable in the function
[/code]
The file you posted has "username" and "password" for the input fields and "usern" and "passw" for the _POST vars. You are including the db connection file in your functions.php and loginscript.php and you are also including functions.php in loginscript.php.[/QUOTE]
[CODE]Username: <input type="text" name="uname" id="uname" />
<br/>
<br/>
Password: <input type="password" name="passw" id="passw" />
<br/>
[/CODE]
[code=php]session_start();[/code]
to the main script.[code=php]require_once( ... );[/code]
to include files and safeguard agains loading up the same scripts over an over when they have already been included.[code=php]require("dbconnect.php"); [/code]
[code=php]require_once("dbconnect.php");[/code]
method.[code=php]require( ... );[/code]
not only issues an error on failure, it will also terminate the script that is currently processing, so this could be the cause of the problems.[code=php]<?php
include('functions.php');
require_once('dbconnect.php');
if(isset($_POST['Login']))
{
if($_POST['uname']!='' && $_POST['passw']!='')
{
//Use the input username and password and check against 'users' table
$query = mysql_query('SELECT ID, uname, Active FROM users
WHERE uname = "'.mysql_real_escape_string($_POST['uname']).'" AND pass = "'.mysql_real_escape_string(md5($_POST['passw'])).'"');
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
if($row['Active'] == 1)
{
$_SESSION['user_id'] = $row['ID'];
$_SESSION['logged_in'] = TRUE;
header("Location: inde2.php");
redirect ("index2.php");
}
else {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
}
}
else {
$error = 'Login failed !';
}
}
else {
$error = 'Please user both your username and password to access your account';
}
}
?>
<?php if(isset($error)){ echo $error;}?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" id="username" name="username" size="32" value="" />
<input type="password" id="password" name="password" size="32" value="" />
<input type="submit" name="Login" value="Login" />
</form>[/code]
[code=php]<?php
session_start();
//connect to the database
require_once ("dbconnect.php");
//send the user somewhere else
function redirect($url)
{
ob_start();
header('location: ' . index2.php);
ob_end_flush();
}
//rearranges a date
function rearrangedate($date)
{
$date1 = explode('-', $date);
$newdate = $date1[1] . "-" . $date1[2] . "-" . $date1[0];
echo $newdate;
}
//rearranges a date and time
function rearrangedatetime($datetime)
{
$datetime1 = explode(" ", $datetime);
$date1 = explode('-', $datetime1[0]);
$newdatetime = $date1[1] . "-" . $date1[2] . "-" . $date1[0] . " at " . $datetime1[1];
echo $newdatetime;
}
?> [/code]
Well the prosscing time is a not a big issue for me. My issue is that its not holding the session variable and not redirecting you.[/QUOTE]
so if I turn on output buffering the header related functions will work?[/QUOTE]
I did that, but it is still giving those two errors and decided to throw this one in there also...
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home2/chicagt7/public_html/loginscript.php:1) in /home2/chicagt7/public_html/functions.php on line 2[/QUOTE]
Note: If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.
Note: Use of zlib.output_compression is recommended rather than ob_gzhandler()
Note: This function will send out several HTTP headers depending on the configuration.[/QUOTE]
[code=php]<?php
session_start();
include('functions.php');
require_once('dbconnect.php');
if(isset($_POST['Login']))
{
if($_POST['uname']!='' && $_POST['passw']!='')
{
//Use the input username and password and check against 'users' table
$query = mysql_query('SELECT ID, uname, Active FROM users
WHERE uname = "'.mysql_real_escape_string($_POST['uname']).'" AND pass = "'.mysql_real_escape_string(md5($_POST['passw'])).'"');
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
if($row['Active'] == 1)
{
$_SESSION['user_id'] = $row['ID'];
$_SESSION['logged_in'] = TRUE;
header("Location: inde2.php");
redirect ("index2.php");
}
else {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
}
}
else {
$error = 'Login failed !';
}
}
else {
$error = 'Please user both your username and password to access your account';
}
}
?>
<?php if(isset($error)){ echo $error;}?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" id="username" name="username" size="32" value="" />
<input type="password" id="password" name="password" size="32" value="" />
<input type="submit" name="Login" value="Login" />
</form>[/code]
[code=php]<?php
//connect to the database
require_once ("dbconnect.php");
//send the user somewhere else
function redirect($url)
{
ob_start();
header('location: ' . index2.php);
ob_end_flush();
}
//rearranges a date
function rearrangedate($date)
{
$date1 = explode('-', $date);
$newdate = $date1[1] . "-" . $date1[2] . "-" . $date1[0];
echo $newdate;
}
//rearranges a date and time
function rearrangedatetime($datetime)
{
$datetime1 = explode(" ", $datetime);
$date1 = explode('-', $datetime1[0]);
$newdatetime = $date1[1] . "-" . $date1[2] . "-" . $date1[0] . " at " . $datetime1[1];
echo $newdatetime;
}
?> [/code]
[code=php]redirect ("./index2.php");[/code]
or[code=php]redirect ("../index2.php");[/code]
or[code=php]redirect ("/index2.php");[/code]
or correctly generate an absoloute path to the file.
header('location: ' . index2.php);
[/quote]
[code=php]
header('location: index2.php');
[/code]
Try posting what you have and I'll try to run it on my dev box when I get home. That way we can make sure it isn't some random file encoding with BOM issue and work backwards till we target the culprit.[/QUOTE]
[code=php]<?php
session_start();
include('functions.php');
require_once('dbconnect.php');
if(isset($_POST['Login']))
{
if($_POST['uname']!='' && $_POST['passw']!='')
{
//Use the input username and password and check against 'users' table
$query = mysql_query('SELECT ID, uname, Active FROM users
WHERE uname = "'.mysql_real_escape_string($_POST['uname']).'" AND pass = "'.mysql_real_escape_string(md5($_POST['passw'])).'"');
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
if($row['Active'] == 1)
{
$_SESSION['user_id'] = $row['ID'];
$_SESSION['logged_in'] = TRUE;
header('location: index2.php');
redirect ("index2.php");
}
else {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
}
}
else {
$error = 'Login failed !';
}
}
else {
$error = 'Please user both your username and password to access your account';
}
}
?>
<?php if(isset($error)){ echo $error;}?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" id="username" name="username" size="32" value="" />
<input type="password" id="password" name="password" size="32" value="" />
<input type="submit" name="Login" value="Login" />
</form>[/code]
[code=php]<?php
//connect to the database
require_once ("dbconnect.php");
//send the user somewhere else
function redirect($url)
{
ob_start();
header('location: index2.php');
ob_end_flush();
}
//rearranges a date
function rearrangedate($date)
{
$date1 = explode('-', $date);
$newdate = $date1[1] . "-" . $date1[2] . "-" . $date1[0];
echo $newdate;
}
//rearranges a date and time
function rearrangedatetime($datetime)
{
$datetime1 = explode(" ", $datetime);
$date1 = explode('-', $datetime1[0]);
$newdatetime = $date1[1] . "-" . $date1[2] . "-" . $date1[0] . " at " . $datetime1[1];
echo $newdatetime;
}
?> [/code]
[code=php]<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="Aviation, Chicago, FSX, server, ATC, Teamspeak, Fleet, Chicago Aviation, Chicago FSX ATC" />
<meta name="description" content="FSX server for flying withor without ATC." />
<title>Chicago Aviation-Where Dreams Take Flight! | Home</title>
<link href="index.css" type="text/css" rel="stylesheet"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="images/favicon.ico" rel="SHORTCUT ICON" />
<style type="text/css">
.style1 {
color: #FFFFFF;}
.style2 {
text-decoration: none;
}
</style>
<script type="text/javascript">
<!--
function FP_swapImg() {//v1.0
var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
elm.$src=elm.src; elm.src=args[n+1]; } }
}
function FP_preloadImgs() {//v1.0
var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}
function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
return null;
}
// -->
</script>
<script type="php"></script>
</head>
<body onload="FP_preloadImgs(/*url*/'buttonjoin2.gif')">
<div id="main-content">
<img src="images/CAHeader.jpg" alt="Header"/>
<a href="index2.php">Home</a> <span class="style1">|</span> <? /*if the user is logged in*/ if($_SESSION['logged']==1){ /* show the downloads test page*/?>
<a href="members/downloads.php">Downloads</a> <? }else{ /* otherwise show the other one*/?><a href="login.php">Downloads</a><? } ?><span class="style1">
|</span> <a href="weather.php">Weather</a> <span class="style1">|</span>
<a href="aboutus.php">About Us</a><span class="style1"> |</span>
<a href="gallery.php">Gallery</a> <span class="style1">|</span>
<a href="forums.php">Forums</a><span class="style1"> |</span>
<a href="members/members.php">Members</a><? if($_SESSION['logged']==1){ /* if the user is logged in display member area links*/ ?>
<span class="style1">|</span> <a href="members/stinfo.php">Server info &
Team speak info</a>
<span class="style1">|</span>
<a href="members/links.php">Links</a> <span class="style1">|</span>
<a href="members/flightservices.php">Flight Services</a> <span class="style1">|</span>
<a href="bios/calendar.php">Events Calendar</a><? } ?>
<br/>
<img id="ts" src="http://www.tsviewer.com/promotion/dynamic_sig/sig.php/clan160x283_fs/57883.png" width="160" height="283" alt="TS Viewer" />
<br/>
<img id="welcome" src="images/Welcome.png" alt="Welcome to Chciago Aviation"/>
<br/>
<a href="register.php">
<img style="border: 0" id="join" src="images/buttonjoin.gif" height="20" width="100" alt="Join Now!" onmousedown="FP_swapImg(1,0,/*id*/'img1',/*url*/'images/buttonjoin2.gif')" onmouseup="FP_swapImg(0,0,/*id*/'img1',/*url*/'images/buttonjoin.gif')" /></a>
<object id="youtube" type="application/x-shockwave-flash" style="width:425px; height:350px;" data="http://www.youtube.com/v/aoVkSS-xCaE"><param name="movie" value="http://www.youtube.com/v/aoVkSS-xCaE" /><param name="wmode" value="transparent"></param></object>
<p id="p1">Well Let me be the first to say welcome To Chicago Aviation!<br />
We run a 24/7 Teamspeak server with a server in <acronym title="Flight Simulator X">
FSX</acronym>. We try to have a different edge than the other servers<br /> and
by that we mean, we take care of our members, and help them find a aircraft that
they are comfortable in<br /> and we help them get the most out of <acronym title="Flight Simulator X">
FSX</acronym>. </p>
<p>We don't do the regular same place day in and out. We go around the world to
see the stunning beauty of <acronym title="Flight Simulator X">FSX</acronym><br />
and to challenge our selves and have fun doing it! We host a <abbr title="Air Traffic Control">
ATC</abbr> session once in a while but we try to be different<br /> but if you
want more <abbr title="Air Traffic Control">ATC</abbr> tell us in the forums and
we will set it up for you. This is done for you to enjoy this and not only us.</p>
<p>If you would like to become a member of Chicago Aviation please register with
the website and become a member of the forums.<br />
Also there are perks of becoming a member like a weekly newsletter that is made
by our very own Director of <abbr title="Virtual Airline">VA</abbr> <abbr title="Operations">
Ops</abbr> <br />
with the help of our real world pilot for <abbr title="United Airlines">UAL</abbr>,
downloadable fleet, and much much more! </p>
<p id="contact">If you have any questions or comments e-mail us at:<br />
<a href="mailto:[email protected]?subject=Website">
[email protected]</a></p>
<p id="contact2">
<img src="images/Star_Alliance_Virtual.jpg" alt="Star Allicane" />
<br/>
Click <a href="mail">
Here</a>
to log into your Chicago Aviation E-mail account.
</p>
<p id="bottom_links">
<a href="index2.php">Home</a><a href="index2.php" class="style2"><span> | </span></a>
<a href="register.php">Join Us</a><a href="register.php" class="style2"> | </a>
<a href="contact.php">Contact Us</a><a href="contact.php" class="style2"> | </a>
<a href="termsofuse.php">Terms of Use</a>
</p>
<p id="copyright">© Chicago Aviation <br />United Virtual Airlines CA is a
Virtual Airline for Flight Simulation. The United Air Lines Logos and Trademark
on this site remain the property of United Air Lines, Inc. The Chicago Aviation
Logos and Trademark on this site remain the property of Chicago Aviation. No
part of this Website Design or Layout may be reproduced or transmitted in any
form or by any other means, electronic, mechanical (including photocopying,
recording) or by any information storage and retrieval system, without the
express permission of Chicago Aviation. 2007-2008 All rights reserved ®</p>
</div>
<p id="css_valid">
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img style="border:0;width:88px;height:31px"
src="http://jigsaw.w3.org/css-validator/images/vcss"
alt="Valid CSS!" />
</a>
<a href="http://www.vatsim.net/"><img alt="Vatsim Spin logo" src="http://www.united-virtual.com/images/pagemaster/VATSIM_2.gif"/></a>
</p>
<!-- Copyright Tom Brodowski 2007-2008 for Chicago Avition. All Rights Resvered-->
</body>
</html>
[/code]
[code=php]
$_SESSION['logged']=TRUE;
[/code]
[code=php]
if($_SESSION['logged']==1)
[/code]
You are setting the session var as
[code=php]
$_SESSION['logged']=TRUE;
[/code]
and checking it with:
[code=php]
[/QUOTE]
if($_SESSION['logged']==1)
[/code]
0.1.9 — BETA 5.13