Jump to content

mysql_connect error sending headers


es131245
 Share

Recommended Posts

if(isset($_POST['login'])&&isset($_POST['password'])){if($_POST['login']==''||$_POST['login']=='login'||$_POST['password']==''||$_POST['password']=='password'{header('location:http://site.com/?act=error&code=100');} $mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password) or header('location:http://site.com/?act=error&code=200'); $mysql_select_db=mysql_select_db($mysql_database) or header('location:http://site.com/?act=error&code=201'); ... mysql_close($mysql_connect);}

it work well exept if mysql_connection failin that case line

 $mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password) or header('location:http://site.com/?act=error&code=200');

sends headers and it fails to

 header('location:http://site.com/?act=error&code=200');

all i want to is use header if it fails to connectand i dont want to use die()

Link to comment
Share on other sites

couple things: read the manual for casing, i.e.

 header('Location: http://site.com/page.php?act=error&code=200');

http://php.net/manual/en/function.header.phpit doesn't work, try sending it to a specific page try

header('location:http://site.com/page.php?act=error&code=200');

and then that page should handle the values of act and code, if the intention is to display a custom error message to the user

Edited by thescientist
Link to comment
Share on other sites

nope =)it workes well for DATABASE NOT FOUND error =)))same page + index-file.names = ("index.php","index.html")site.com/?act=error == site.com/index.php?act=errorive tryed :)thats the point it worked for databases but not for connecting

Edited by es131245
Link to comment
Share on other sites

Okay, so I understood nearly nothing of what you just said in your latest reply, and just a bit more in the original post.Is it working now or is it still not working?Your saying that the one line where you're trying to connect it's not correctly sending header when it fails, but on the next line where it tries to select a database, when that fails it does correctly send the header?

Link to comment
Share on other sites

$mysql_user='user'; $mysql_password='pass';$mysql_host='localhost'; $mysql_database='dabe';$_POST['login']='l'; $_POST['password']='p';if(isset($_POST['login'])&&isset($_POST['password'])){if($_POST['login']==''||$_POST['login']=='login'||$_POST['password']==''||$_POST['password']=='password'){header('l $mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password) or header('location:http://site.com/?act=error&code=200'); $mysql_select_db=mysql_select_db($mysql_database) or header('location:http://site.com/?act=error&code=201'); mysql_close($mysql_connect); die('good');}>>>>>GOOD$mysql_user='user'; $mysql_password='pass';$mysql_host='localhost'; $mysql_database='WRONG DATABASE';$_POST['login']='l'; $_POST['password']='p';if(isset($_POST['login'])&&isset($_POST['password'])){if($_POST['login']==''||$_POST['login']=='login'||$_POST['password']==''||$_POST['password']=='password'){header('l $mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password) or header('location:http://site.com/?act=error&code=200'); $mysql_select_db=mysql_select_db($mysql_database) or header('location:http://site.com/?act=error&code=201'); mysql_close($mysql_connect); die('good');}>>>>>Error 201 DATABASE ERROR$mysql_user='WRONG USER'; $mysql_password='pass';$mysql_host='localhost'; $mysql_database='dabe';$_POST['login']='l'; $_POST['password']='p';if(isset($_POST['login'])&&isset($_POST['password'])){if($_POST['login']==''||$_POST['login']=='login'||$_POST['password']==''||$_POST['password']=='password'){header('l $mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password) or header('location:http://site.com/?act=error&code=200'); $mysql_select_db=mysql_select_db($mysql_database) or header('location:http://site.com/?act=error&code=201'); mysql_close($mysql_connect); die('good');}>>>>> mysql connection access DENIEDheaders already send in $mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password) or header('location:http://site.com/?act=error&code=200');mysql_select_db() error mysql close erroroO

Link to comment
Share on other sites

thats the problemheaders already send in$mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password) or header('location:http://site.com/?act=error&code=200');mysql_connection function sends header then it fails

Link to comment
Share on other sites

If you look at the end of this line:

{if($_POST['login']==''||$_POST['login']=='login'||$_POST['password']==''||$_POST['password']=='password'){header('l

What is that header('l bit? Looks like you mis-copy/pasted, or forgot to delete this bit. Take it out.

Edited by Miss_Rebelx
Link to comment
Share on other sites

if($_POST['login']==''||$_POST['login']=='login'||$_POST['password']==''||$_POST['password']=='password'){header('location: http://y-es.ru/?act=error&code=100');}

if(isset($_POST['login'])&&isset($_POST['password'])){if($_POST['login']==''||$_POST['login']=='login'||$_POST['password']==''||$_POST['password']=='password'){header('location: http://site.com/?act=error&code=100');} $mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password) or header('location: http://site.com/?act=error&code=200'); $mysql_select_db=mysql_select_db($mysql_database) or header('location: http://site.com/?act=error&code=201'); mysql_close($mysql_connect);}?>

Link to comment
Share on other sites

I'm assuming you've tried it and it didn't work, with the same results.Though, since you didn't specify, I will ask:If this edit didn't fix it, can you please post the error code (copy paste, not re-writing it in your own words... feel free to take out any information from the error message you feel is private), and then can you copy paste the line that it says is causing the error?Also, I'm not sure you can even send someone to "/?variable=value". Maybe I'm wrong, but I thought you had to send someone to a php page, then append to it the GET SQL string (/page.php?variable=value).

Link to comment
Share on other sites

$mysql_user='WRONG USER';$mysql_password='pass';$mysql_host='host'';$mysql_database='sitedb';if(isset($_POST['login'])&&isset($_POST['password'])){if($_POST['login']==''||$_POST['login']=='login'||$_POST['password']==''||$_POST['password']=='password'){header('location: http://site.com/?act=error&code=100');die();} if(!$mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password)){header('location: http://site.com/?act=error&code=200');die();} if(!$mysql_select_db=mysql_select_db($mysql_database)){header('location: http://site.com/?act=error&code=201');die();} mysql_close($mysql_connect); die('good');}Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'WRONG'@'host' (using password: YES) in *.php on line 47Warning: Cannot modify header information - headers already sent by (output started at *.php:47) in *.php on line 47$mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password);some how starts an output oO

Link to comment
Share on other sites

if(!$mysql_connect=mysql_connect($mysql_host,$mysql_user,$mysql_password)){die('<script type="text/javascript">window.location.href=\'http://site.com/?act=error&code=200\';</script>');}that works but doent explain anything

Link to comment
Share on other sites

I think that what's happened is mysql_connect() is generating an error message, thereby starting the output and preventing headers from being sent. You can use the "@" operator to prevent this, i.e.

if(!$mysql_connect=@mysql_connect($mysql_host,$mysql_user,$mysql_password)){header('location: http://site.com/?act=error&code=200');die();}

More info at http://uk3.php.net/manual/en/language.oper...rrorcontrol.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...