473,385 Members | 1,218 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,385 software developers and data experts.

Warning: Cannot modify header information

I looked all over the web, and i just cant find the answer.. how can i do this? I want that when the user inputs an invalid username or password my page would automatically redirect to the log.in page..

a snippet of the problem area..

Expand|Select|Wrap|Line Numbers
  1. if(!($dbh=@mysql_connect($host,$username,$password)))
  2.    { header('Location:index.html');
  3.      //print "<a href=http://localhost/pms/index.html>Back to login.</a><br>";
  4.      //print "access denied.";
  5.    }     
  6.  
  7.  
the warning is at
(output started at C:\xampp\htdocs\PMS\login.php:2) in C:\xampp\htdocs\PMS\login.php on line 13
line 13 is the if statement.. i tried suppressing the warning, but it still wont work!.. :( any ideas??
Feb 1 '10 #1
4 1214
zorgi
431 Expert 256MB
Give us more code as this error is issued when headers are already sent. You can not have any output before redirection. Even white space before opening tag will result in this error.
Feb 1 '10 #2
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $username=$_POST["UsernameBox"];
  4. $password=$_POST["PasswordBox"];
  5. $host="localhost";
  6.  
  7.  
  8.    //error_reporting(0);  
  9.  
  10.  
  11. if(!($dbh=@mysql_connect($host,$username,$password)))
  12.    { header('Location:index.html');
  13.      //print "<a href=http://localhost/pms/index.html>Back to login.</a><br>";
  14.      //print "access denied.";
  15.    }       
  16. else  
  17.    { print "sample login....";    
  18.      mysql_close($dbh);
  19.  
  20.    }  
  21.  
  22.  
  23.  
  24. ?>
  25.  
this is just about it..
Feb 1 '10 #3
zorgi
431 Expert 256MB
Ok

mysql_connect opens connection to a MySQL Server and user should not have anything to do with it. Big NO NO NO. Security Alarm :)))

There is loads of tutorials on how to make Login Script using php. I only searched for a second and found this:

http://www.phpeasystep.com/workshopview.php?id=6

I must say I didn't try it but it looks ok.

Good Luck
Feb 1 '10 #4
Atli
5,058 Expert 4TB
@ronolivar
Really? This is one of the more common problems people face when starting out with PHP. There are literally hundreds of threads on this topic here at Bytes.

But anyways. You should start by readin through this article draft by Markus. It deals specifically with this problem.

If you can't locate it, post the first ~20 lines of your login.php script and we will take a look and see if we can spot it.
Feb 1 '10 #5

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

Similar topics

1
by: None | last post by:
Hello, I am a total newbie to PHP and programming in general. I am playing around with a PHP / MySQL shopping cart script which I found at...
3
by: Greg Scharlemann | last post by:
Does the redirect statement: header(Location:"http://www.newpage.com"); need to come before certain statements? I've setup a login page and try to redirect a user once they have logged in...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
4
by: kempy535 | last post by:
Hi I get this error code when I try to run my login script. Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\Rising...
5
by: nasse | last post by:
I am getting the following error msg whenever I try to login. I tried to turn my output_buffering = On in my php.ini but is not working for me. Would you please help me: Warning: Cannot modify...
8
by: mcserret | last post by:
I know this is a recurring problem that has been addressed here before, but even after reading all that has gone before, I am still stumped. I have a form that is designed to send data to a PHP...
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: mrosado | last post by:
Hi everybody, I have this problem.- The browser launch this two errors: Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at...
3
by: gubbachchi | last post by:
Hi, I have written php code to retrive the image from mysql and display it on the webpage. Here is the code <?php require_once("DBConnect.php"); $gotten = @mysql_query("select user_photo from...
10
by: jessica87 | last post by:
hi there, i m using this coding to retrieve the file from database so that my user can download the file... <?php if (!isset($_GET)) die('Invalid Parameter'); include...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.