Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 14th, 2003, 10:39 AM
amirzol amirzol is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 amirzol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
one week php old going to be crazy

I do not know how can i get rid of this message " Warning: Cannot add header information - headers already sent by (output started at C:\FoxServ\www\myPHP\login.php:9) in C:\FoxServ\www\myPHP\login.php on line 14 "

I'm just trying to run login tutorial, i got two pages one "login.htm" has the login form, fields and submit button which u r all familar with and the other page "login.php" includes the following lines excluding the html stuff:

<?PHP
//check that the user is calling the page from the login form and not accessing it directly
//and redirect back to the login form if necessary
if (!isset($username) || !isset($password)) {
ob_flush();
header( "Location: localhost/login.htm" );
// include 'login1.php'; <---- have a look later
}
//check that the form fields are not empty, and redirect back to the login page if they are
elseif (empty($username) || empty($password)) {
ob_flush();
header( "Location: localhost/login.htm" );
}
else{

//convert the field values to simple variables

//add slashes to the username and md5() the password
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);


//set the database connection variables

$dbHost = "localhost";
$dbUser = "amirzol";
$dbPass = "donotpass";
$dbDatabase = "dbase1";

//connet to the database

$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");

mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

$result=mysql_query("select * from users where username='$user' AND password='$pass'", $db);

//check that at least one row was returned

$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result)){

//start the session and register a variable

session_start();
session_register('username');

//successful login code will go here...
echo 'Success!';

//we will redirect the user to another page where we will make sure they're logged in
header( "Location: checkLogin.php" );

}

}
else {

//if nothing is returned by the query, unsuccessful login code goes here...

echo 'Incorrect login name or password. Please try again.';
}
}
?>



Reply With Quote
  #2  
Old September 14th, 2003, 11:22 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to thecharking
how i do this

okay as far as I can tell, the code is not the problem.. I mean i didnt look at it, but this problem originates in that before you start doing any php, you can't send headers, meaning no html ( i am most likely wrong on ho this actually works). At any rate... I jsut add this to the top of each php page i use:
PHP Code:
<?php ob_start(); ?>

This with no spaces, no white space at the beginning; nothing, just that first. And I use an index.php page, and then includes to show other pages, which also makes for good, consistent design; but also means I jsut put ob_start() at the beginning of index.php and it basically flows down the page.
If I'm wrong, go ahead and correct me... I'm just excited I can answer this question!
__________________
hey it's the CHARKING

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > one week php old going to be crazy


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap