Hello all, I have a site with login system, when I run it on my local sever it worked perfectly ok, but when uploaded it was not taking me to member page as on my local server.

Please can anybody help me with this.

The codes are below.

myconfig.php

<?php
$con=mysql_connect("localhost","leomconn_leom","happiness100");
if(!$con)
{
die("Database connection failed: ".mysql_error());
}

//selecting the database and inserting into the database
mysql_select_db("leomconn_leomdatabase",$con);
?>

registered.php

<?php 
if (isset($_POST['Submit']))
{
	include("myconfig.php");
	$username = $_POST["username"];
	$password = $_POST["password"];
	
	
	$check = mysql_query("SELECT * FROM registered WHERE username = '$username'");
	if(mysql_num_rows($check)==0)
	{
		$ins = mysql_query("INSERT INTO registered(username, password) VALUES('$username', '$password')");
		echo "<br/>";
		echo "<font color=#000000  size=+2> Entered Succefully</font>"; echo "<br/>";
		echo "<br/>";
				}
		else
		{
		echo "<font color=#000000 size=+2> Username already exist</font><br/>";
		}
}
?>

index.php

<?php

if(isset($_POST['Submit']))
{
	include("myconfig.php");
	$username=$_POST["username"];
	$password=$_POST["password"];
	$check=mysql_query("select * from registered where username='$username' AND password='$password'");
	if(mysql_num_rows($check)==0)
	echo "<font color=#0000FF>Make Payment to be activated </font><br/>";
	
	//creatinga a sersion and header that redirects it to the page called secret.php
	else
	{
	$_SESSION[xyz]=$username;
	// the secret.php page is the page the user goes after he logs in succefully
	header("Location:member.php");
	
	}
}

?>

I will really appreciate if anybody can help me out.

thanks all

Treasurepet

Dani AI

Generated

A short diagnosis and practical checklist that complements the thread (ties together and ), plus a few longer‑term fixes.

The immediate error (“Cannot modify header information — headers already sent…”) means PHP tried to send HTTP headers after output had already started; header() and cookie/session functions must run before any output. The PHP docs explain this and show how to detect where output started (headers_sent()). header() docs. (php.net) (php.net)

Quick checklist to locate the culprit (common causes seen in this thread)

  • Check every included file for stray whitespace or blank lines before the opening <?php and after a closing ?>. Omit the closing PHP tag on pure-PHP files.
  • Check for a UTF‑8 BOM (files saved as “UTF‑8 with BOM” send invisible bytes that count as output). Editors can save “UTF‑8 (no BOM)”. See discussion/examples about BOM causing header problems. (stackoverflow.com)
  • Use headers_sent($file,$line) to get the filename/line where output began; that points to the offending include. (php.net)

Safe fixes and best practices (short + long term)

  • Start sessions and perform redirects before any output: call session_start() at the top of any page that uses $_SESSION, then run login checks and header('Location: ...') followed by exit;. The session docs note cookie‑based sessions must start before output. (php.net)
  • ob_start() (output buffering) is a valid temporary workaround (as suggested and as the OP noted it worked), but removing the root cause (whitespace/BOM or misplaced HTML) is preferable for a reliable fix.
  • Don’t rely on the old mysql_* API shown in the code: it was deprecated and removed in modern PHP. Migrate to PDO or MySQLi with prepared statements and use password_hash()/password_verify() for passwords rather than storing plaintext. See the PHP notes on ext/mysql removal, PDO prepared statements, and password_hash(). (php.net)

A combination of the checklist above and moving session/redirect logic to the top of the script usually resolves this class of problem permanently.

Recommended Answers

All 17 Replies

Member Avatar for Member #120589

have you changed the DB login details?

have you changed the DB login details?

Yes I have done that

Member Avatar for Member #120589

you seem to be missing braces.
Also enclose array keys in quotes.
Also set session_start() - you don't seem to have that so sessions shouldn't work.

if(mysql_num_rows($check)==0)  //SHOULD BE A { HERE
echo "<font color=#0000FF>Make Payment to be activated </font><br/>";

//creatinga a sersion and header that redirects it to the page called secret.php
//SHOULD BE A } HERE
else
{
$_SESSION[xyz]=$username; //MAKE THIS $_SESSION['xyz']
// the secret.php page is the page the user goes after he logs in succefully
header("Location:member.php");

}

Are you sure you got this to work on localhost?

you seem to be missing braces.
Also enclose array keys in quotes.
Also set session_start() - you don't seem to have that so sessions shouldn't work.

if(mysql_num_rows($check)==0)  //SHOULD BE A { HERE
echo "<font color=#0000FF>Make Payment to be activated </font><br/>";

//creatinga a sersion and header that redirects it to the page called secret.php
//SHOULD BE A } HERE
else
{
$_SESSION[xyz]=$username; //MAKE THIS $_SESSION['xyz']
// the secret.php page is the page the user goes after he logs in succefully
header("Location:member.php");

}

Are you sure you got this to work on localhost?

I have made the changes and it does not work, I also set session_start(), is running fine on my localhost...I don't really know the problem. I

I have made the changes and it does not work, I also set session_start(), is running fine on my localhost...I don't really know the problem. I

Hello all, can anybody help? I have tried all I could but still cannot redirect to member.php, instead this is the error am getting.

PLEASE HELP


Warning: Cannot modify header information - headers already sent by (output started at /home/leomconn/public_html/index.php:9) in /home/leomconn/public_html/index.php on line 190

Please I need somebody to help

Member Avatar for Member #120589

You can't use header() if you have output to the page (e.g. static html or php output like echo or any whitespace).

You can't use header() if you have output to the page (e.g. static html or php output like echo or any whitespace).

Thanks for your response, Please what do I do from here am a newbie, can you please help me with what to do again. thanks

Member Avatar for Member #120589

I've told you - you can't use header() if you've already outputted something to the page. Ensure that all (or most) your php is above the Doctype Declaration and that you don't echo anything before the header(). You can save stuff to be outputted in variables until you need to output them in the relevant area of the page itself.

I've told you - you can't use header() if you've already outputted something to the page. Ensure that all (or most) your php is above the Doctype Declaration and that you don't echo anything before the header(). You can save stuff to be outputted in variables until you need to output them in the relevant area of the page itself.

Thanks so much for your responses and advice, I have tried all I could, moved all I could but still getting the same thing, Please can you help me re-modified the code.


myconfig.php

<?php
$con=mysql_connect("localhost","leomconn_leom","happiness100");
if(!$con)
{
die("Database connection failed: ".mysql_error());
}

//selecting the database and inserting into the database
mysql_select_db("leomconn_leomdatabase",$con);
?>


registered.php
<?php
if (isset($_POST))
{
include("myconfig.php");
$username = $_POST["username"];
$password = $_POST["password"];


$check = mysql_query("SELECT * FROM registered WHERE username = '$username'");
if(mysql_num_rows($check)==0)
{
$ins = mysql_query("INSERT INTO registered(username, password) VALUES('$username', '$password')");
echo "<br/>";
echo "<font color=#000000 size=+2> Entered Succefully</font>"; echo "<br/>";
echo "<br/>";
}
else
{
echo "<font color=#000000 size=+2> Username already exist</font><br/>";
}
}
?>

index.php
<?php

if(isset($_POST))
{
include("myconfig.php");
$username=$_POST["username"];
$password=$_POST["password"];
$check=mysql_query("select * from registered where username='$username' AND password='$password'");
if(mysql_num_rows($check)==0)
echo "<font color=#0000FF>Make Payment to be activated </font><br/>";

//creatinga a sersion and header that redirects it to the page called secret.php
else
{
$_SESSION[xyz]=$username;
// the secret.php page is the page the user goes after he logs in succefully
header("Location:member.php");

}
}

?>

thanks all the while.

Warning: Cannot modify header information - headers already sent by (output started at /home/leomconn/public_html/index.php:9) in /home/leomconn/public_html/index.php on line 190

Please I need somebody to help

As ardav said you cannot do that but there is a workaround. Use ob_start. If you want to know why, someone did took a trouble of explaining here

You can try

echo "<meta http-equiv='refresh' content='0;url=http://localhost/project/'>";
for redirection instead of header if same issue exist.

Are you sure you are redirecting to the correct page as this information is conflicting:

// the secret.php page is the page the user goes after he logs in successfully
header("Location:member.php");

You say they are redirected to secret.php when logged in successfully but in your header location you are redirecting to member.php.

Just a thought

Are you sure you are redirecting to the correct page as this information is conflicting:

// the secret.php page is the page the user goes after he logs in successfully
header("Location:member.php");

You say they are redirected to secret.php when logged in successfully but in your header location you are redirecting to member.php.

Just a thought

Yes, am redirecting to correct page, the secret.php is just in comment, the page is actually member.php

Yes, am redirecting to correct page, the secret.php is just in comment, the page is actually member.php

I know the problem but the way to solution is what I don't know, where and where will I place my header is the problem.

Instead of

$check=mysql_query("select * from registered where username='$username' AND password='$password'");

Try:

$query = "select * from registered where username='$username' AND password='$password'";

$check = mysql_num_rows($query);

Instead of

$check=mysql_query("select * from registered where username='$username' AND password='$password'");

Try:

$query = "select * from registered where username='$username' AND password='$password'";

$check = mysql_num_rows($query);

Thanks all, I was able to fix the error after lots of troubleshooting using

ob_start() and ob_flush()

thanks

Thanks all, I was able to fix the error after lots of troubleshooting

Yeah that is right because you don't read the answers given here. IF only you have worked on my post quoted below, you could have saved yourself alot of pains

As ardav said you cannot do that but there is a workaround. Use ob_start. If you want to know why, someone did took a trouble of explaining here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.