473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Cannot modify header information - headers already sent by (output started at I:\xamp

What is wrong with this code? This code has been given to me by one of my friends and told me to help him troubleshoot. I am using xampp 1.7.3 installed in the I: drive and my OS is win xp.
I created a .htaccess file and .htpass file in C drive under "C:\secret" folder.
.htaccess script -


Expand|Select|Wrap|Line Numbers
  1.   AuthUserFile "C:\secret\.htpass
  2.     AuthGroupFile /dev/null
  3.     Authame "Accounting Department"
  4.     AuthType Basic
  5.     Require valid-user

.htpass file contains the name and password.
Vars.inc contains this code-


Expand|Select|Wrap|Line Numbers
  1.   <?php
  2.             $host = "localhost";
  3.             $user = "root";
  4.             $passwd = "ABCD";
  5.             $database = "useraccount";
  6.     ?> 
  7.  
And there is "Welcome.inc" file with this code-


Expand|Select|Wrap|Line Numbers
  1.  <?php
  2.     /* File: Welcome.inc
  3.       * Desc: HTML code that displays the Welcome Web page.
  4.       *       Uses one PHP variable, $user_name.
  5.       */
  6.        echo "<html><head><title>Welcome</title></head>\n
  7.              <body>
  8.              <p align='center'>Hello, $user_name</p>\n
  9.              <p align='center'>Welcome to my secret page</p>\n
  10.              </body></html>";
  11.     ?>

I have created a database "useraccount" and a table "valid_user" in it with user_name,password ,create_date fields and then filled the "valid_user" table with data.
Now when I run the below code ,instead of a pop-window asking for username and password ,it shows directly "The User Name or password you entered is not valid." in the browser.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     /* Program: Auth.php
  3.     * Desc:    Program that prompts for a user name and
  4.     *          password from the user using HTTP authentication.
  5.     *          The program then tests whether the user
  6.     *          name and password match a user name and password
  7.     *          pair stored in a MySQL database.
  8.     */
  9.  
  10.     if(!isset($_SERVER['PHP_AUTH_USER']))                   
  11.     {
  12.         header('WWW-Authenticate: Basic realm="secret section"');
  13.         header('HTTP/1.0 401 Unauthorized');                 
  14.         exit("This page requires authentication!");           
  15.     }                                                     
  16.  
  17.     else                                                   
  18.     {
  19.         include("Vars.inc");                                 
  20.         $user_name = trim($_SERVER['PHP_AUTH_USER']);       
  21.         $user_password = trim($_SERVER['PHP_AUTH_PW']);
  22.     $connection = mysql_connect($host,$user,$passwd)   #23
  23.                    or die ("Couldn't connect to server.");   
  24.         $db = mysql_select_db($connection,$database)
  25.                    or die ("Couldn't select database.");
  26.         $sql = "SELECT user_name FROM Valid_User
  27.                     WHERE user_name = '$user_name'
  28.                     AND password = md5('$user_password')";
  29.         $result = mysql_query($connection,$sql)
  30.                       or die("Couldn't execute query.");     
  31.         $num = mysql_num_rows($result);                     
  32.         if ($num < 1)         
  33.         {
  34.            exit("The User Name or password you entered
  35.                         is not valid.<br>");
  36.         }                                                     
  37.     }                                                       
  38. include("Welcome.inc");                                 
  39.     ?>
  40.  
Is the above code OK?
1)I have doubt as to whether the "passwd" will be "password" in line #23 above as the Vars.inc file contains "passwd" ?
2)Also will I have to put real values for $user,$host ,$password ,$database ?
3)should the $user be root which is my mysql username and the $password my mysql password?
4)The error is sometimes "The User Name or password you entered is not valid."
I referred to the articles in this same forum -
A)http://bytes.com/topic/php/answers/7...-php-line-10-a
B)http://bytes.com/topic/php/answers/7...-php-line-11-a
but still my problem remains.
Now the error is in line #23,the browser gives the following error -
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'localhost' (using password: YES) in I:\xampp\htdocs\test\test1\Auth.php on
line 23 Couldn't connect to server.
I am totally confused .
Please help.
Aug 22 '11 #1
1 1933
use this function at the top of the file :

ob_start();
May 17 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Phyzlo | last post by:
Hello, I've recently started learning PHP and have a question. I tried running below script which can be found at http://se2.php.net/manual/sv/function.setcookie.php but I keep getting this...
5
by: J Huntley Palmer | last post by:
I am getting this error: Cannot modify header information - headers already sent by when I issue a header ("Location: http://www.foobar.com"); How can I redirect the user to such a site...
5
by: half21back | last post by:
Can anyone tell me what is wrong with this code? <?php if (isset($_COOKIE)) { $url = $row_rsCookieReferral; header("Location: $url"); } ?>
2
by: smartic | last post by:
I'm having problem with header redirection that is my code: <?php header("location:Redirecting.php"); exit; ?> //Then the HTML It give me an error
3
by: TechnoAtif | last post by:
Hi All. I have got problem with the header. If i run my php script in the local host it runs perfectly but if i do the same on net after loading it via ftp. it gives following error: The code...
5
by: mukeshrasm | last post by:
Hi I am working on gd library with PHP to create graphs which is displaying correctly. But I want to display some information about this graph as text which will not be part of this graph means...
2
by: pks83 | last post by:
Hello I am also facing this problem when i amtrying to send additional header information. Warning: Cannot modify header information - headers already sent by (output started at header.php:96)...
2
by: creative1 | last post by:
I get following error on page : Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\desiorb\411.php:9) in C:\xampp\htdocs\desiorb\411.php on line 21 when...
4
by: JRough | last post by:
I have this section at the end of a page ------------------- if ($_POST== 'Open in Excel'){ if (empty($data)) { $data = "\n(0) Records Found!\n";} header("Content-type:...
3
by: dannynez | last post by:
my problem is in line 58 - header("Location: ".$MM_redirectLoginSuccess); and in line 61-header("Location: ".$MM_redirectLoginFailed); i get this (Warning: Cannot modify header information -...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.