Jump to content

Recommended Posts

Hello folks,

I am trying to redirect from login page to logged in page, but using the {header( 'Location: C:\wamp\www' ) ;} is giving me this error {

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\password.php:14) in C:\wamp\www\password.php on line 35}, find below my code

 

 

<?php

echo <<<htmlmsg

<html><center><FORM action="" method=GET><FIELDSET>

<LEGEND>User Login</LEGEND><P>

Email: <INPUT type=text NAME="email">

Username: <INPUT type=text NAME="username"><br>

<INPUT TYPE=submit NAME=submit VALUE=submit>

<input type=reset name=reset value=reset>

</FIELDSET><P>

</FORM>

</html>

 

 

htmlmsg;

 

$dbConnect=mysql_pconnect("localhost", "root") or die("Cannot connect database");

mysql_select_db("test") or die("Cannot select database");

 

 

$user=$_GET['username'];

$mail=$_GET['email'];

 

if ($_GET['submit'])

 

{

 

$query="select `usrName`, `email` FROM enduser WHERE `usrName`='$user' AND `email`='$mail'";

 

$result=mysql_query($query);

$count=mysql_num_rows($result);

 

 

if ($count==1)

{

header( 'Location: C:\wamp\www' ) ;

 

} else echo "No match found !";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/46309-warning-cannot-modify-header-information/
Share on other sites

You are echo'ing HTML/text before you use the header function. You should call the header function before you send any output to the browser.

 

What I'd do is this:

<?php

$html = <<<htmlmsg
<center><FORM action="" method=GET><FIELDSET>
<LEGEND>User Login</LEGEND><P>
Email: <INPUT type=text NAME="email">
Username: <INPUT type=text NAME="username">

<INPUT TYPE=submit NAME=submit VALUE=submit>
<input type=reset name=reset value=reset>
</FIELDSET><P>
</FORM>
htmlmsg;

$dbConnect = mysql_pconnect("localhost", "root") or die("Cannot connect database");
mysql_select_db("test") or die("Cannot select database");


$user = $_GET['username'];
$mail = $_GET['email'];

if (isset($_GET['submit']))
{
    $query = "select `usrName`, `email` FROM enduser   WHERE `usrName`='$user' AND `email`='$mail'";

    $result=mysql_query($query)
    if(mysql_num_rows($result) == 1);
    {
        header( 'Location: C:\wamp\www' ) ;
    }
    else
    {
        echo 'No match found !<hr />';
    }
}

echo $html;

?>

Anyone can help me? I don't know how to write my site.. i have the same problem with the headers.

 

my error:

 

Warning: Cannot modify header information - headers already sent by (output started at /home/ebesfera/public_html/quemtem1amigotem1tesouro/login.php:37) in /home/ebesfera/public_html/quemtem1amigotem1tesouro/login.php on line 287

 

My code:

<?php 
require_once("php".DIRECTORY_SEPARATOR."webpage.php");	

function checkLogin($user, $pass){
	$retval = false;

	$query = "SELECT * FROM users where login=\"".$user."\" and pass=\"$pass\"";
	$result = mysql_query($query) or die("Query failed"); 

	if (mysql_num_rows($result))
		$retval = true;

	mysql_free_result($result); 
	return $retval;
}

function alterPass($old, $new, $confirm){
	if (checkLogin($_SESSION["login"], md5($old))) {
		if ($new != $confirm) {
			return -2;
		}
		else {

			$query = "update users set pass='".md5($new)."' where login = \"".$_SESSION["login"]."\"";
			mysql_query($query) or die("Admin - alter: Não foi possível fazer o update, Query: ".$query);

			return 1;
		}
	}
	return -1;
}
session_cache_limiter("none");
session_start();

require_once("php".DIRECTORY_SEPARATOR."incs.inc");
setSession();
?>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style11 {font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
}
.style14 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #FFFFFF; }
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #CC0701; font-size: 11px; font-weight: bold; }
.style5 {	font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.newsfont {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; color: #FFFFFF; }
-->
</style>
<script type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<body onLoad="MM_preloadImages('../images/index_r4_c1_f2.gif','../images/index_r5_c1_f2.gif','../images/index_r8_c1_f2.gif','../images/index_r9_c1_f2.gif','../images/index_r11_c1_f2.gif','../images/index_r12_c1_f2.gif','../images/index_r6_c1_f2.gif','../images/index_r40_c1_f2.gif')">



<table width="760" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="145" bgcolor="#CC0701"><!-- #BeginLibraryItem "/Library/menu_correcto.lbi" -->
      <table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="127"> </td>
        </tr>
        <tr>
          <td><a href="../index.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r4_c11','','../images/index_r4_c1_f2.gif',1)"><img src="../images/index_r4_c1.gif" alt="" name="index_r4_c11" width="145" height="24" border="0" id="index_r4_c11"></a></td>
        </tr>
        <tr>
          <td><a href="../autores_index.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r5_c11','','../images/index_r5_c1_f2.gif',1)"><img src="../images/index_r5_c1.gif" alt="" name="index_r5_c11" width="145" height="19" border="0" id="index_r5_c11"></a></td>
        </tr>
        <tr>
          <td><a href="../novidades.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r8_c11','','../images/index_r8_c1_f2.gif',1)"><img src="../images/index_r8_c1.gif" alt="" name="index_r8_c11" width="145" height="21" border="0" id="index_r8_c11"></a></td>
        </tr>
        <tr>
          <td><a href="../catalogo.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r9_c11','','../images/index_r9_c1_f2.gif',1)"><img src="../images/index_r9_c1.gif" alt="" name="index_r9_c11" width="145" height="20" border="0" id="index_r9_c11"></a></td>
        </tr>
        <tr>
          <td><a href="../noticias.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r11_c11','','../images/index_r11_c1_f2.gif',1)"><img src="../images/index_r11_c1.gif" alt="" name="index_r11_c11" width="145" height="20" border="0" id="index_r11_c11"></a></td>
        </tr>
        <tr>
          <td><a href="../agenda.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r12_c11','','../images/index_r12_c1_f2.gif',1)"><img src="../images/index_r12_c1.gif" alt="" name="index_r12_c11" width="145" height="23" border="0" id="index_r12_c11"></a></td>
        </tr>
        <tr>
          <td><a href="../bestsellers.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r6_c11','','../images/index_r6_c1_f2.gif',1)"><img src="../images/index_r6_c1.gif" alt="" name="index_r6_c11" width="145" height="21" border="0" id="index_r6_c11"></a></td>
        </tr>
        <tr>
          <td><a href="../clipping.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r40_c11','','../images/index_r40_c1_f2.gif',1)"><img src="../images/index_r40_c1.gif" alt="" name="index_r40_c11" width="145" height="20" border="0" id="index_r40_c11"></a></td>
        </tr>
        <tr>
          <td><a href="../sala_imprensa.php"><img src="../images/index_r41_c1.gif" alt="" name="index_r41_c11" width="145" height="23" border="0" id="index_r41_c11"></a></td>
        </tr>
        <tr>
          <td><img name="index_r14_c1" src="../images/index_r14_c1.gif" width="145" height="12" border="0" alt=""></td>
        </tr>
        <tr>
          <td><div align="center"><img name="index_r15_c1" src="../images/index_r15_c1.gif" width="145" height="17" border="0" alt=""> </div></td>
        </tr>
        <tr>
          <td><form action="../teste_newsletter.php" method="POST" name="newsletter" id="newsletter">
            <div align="center"></div>
            <table width="100"  border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td height="35"><div align="right"><span class="newsfont">E-mail: </span>
                          <input name="email" type="text" class="style11" id="email">
                </div></td>
              </tr>
              <tr>
                <td height="40"><div align="right"><span class="newsfont">Nome:</span>
                          <input name="nome" type="text" class="style11" id="nome">
                </div></td>
              </tr>
              <tr>
                <td height="40"><div align="right"><span class="newsfont">Idade:</span>
                          <input name="idade" type="text" class="style11" id="idade">
                </div></td>
              </tr>
              <tr>
                <td height="40"><div align="right"><span class="newsfont">Localidade:</span>
                          <input name="localidade" type="text" class="style11" id="localidade">
                </div></td>
              </tr>
              <tr>
                <td height="40"><div align="right"><span class="newsfont">Profissão: </span>
                          <input name="profissao" type="text" class="style11" id="profissao">
                </div></td>
              </tr>
              <tr>
                <td><img src="../images/spacer.gif" width="10" height="10"></td>
              </tr>
              <tr>
                <td><div align="right">
                  <input name="Submit" type="submit" class="style11" value="inscrever">
                </div></td>
              </tr>
            </table>
          </form></td>
        </tr>
        <tr>
          <td><img name="index_r14_c1" src="../images/index_r14_c1.gif" width="145" height="12" border="0" alt=""></td>
        </tr>
        <tr>
          <td><a href="mailto:geral@esferadoslivros.pt"><img name="index_r20_c1" src="../images/index_r20_c1.gif" width="145" height="58" border="0" alt=""></a></td>
        </tr>
        <tr>
          <td><img name="index_r14_c1" src="../images/index_r14_c1.gif" width="145" height="12" border="0" alt=""></td>
        </tr>
        <tr>
          <td><img name="index_r23_c1" src="../images/index_r23_c1.gif" width="145" height="24" border="0" alt=""></td>
        </tr>
        <tr>
          <td><form name="form3" method="post" action="../pesquisa.php">
            <div align="center">
              <table width="100"  border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td align="right"><input name="pesquisa" type="text" class="style11" id="pesquisa">
                        <span class="style14"> <br>
                        <select name="busca" class="style5" id="busca">
                          <option value="Autor" selected>Autor</option>
                          <option value="Livro">Livro</option>
                          <option value="isbn">ISBN</option>
                        </select>
                      </span></td>
                </tr>
                <tr>
                  <td><img src="../images/spacer.gif" width="10" height="10"></td>
                </tr>
                <tr>
                  <td><div align="right">
                    <input name="Submit" type="submit" class="style5" value="procurar">
                  </div></td>
                </tr>
              </table>
            </div>
          </form></td>
        </tr>
      </table>
    <!-- #EndLibraryItem --></td>
    <td valign="top" background="../images/index_r33_c2.jpg"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="27"> </td>
        <td><table width="100%" height="106"  border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="321"><img name="index_r1_c3" src="../images/index_r1_c3.jpg" width="321" height="106" border="0" alt="1"></td>
            <td valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><img name="index_r1_c11" src="../images/index_r1_c11.jpg" width="267" height="73" border="0" alt="1"></td>
              </tr>
              <tr>
                <td><table  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r2_c111','','images/index_r2_c11_f2.jpg',1)"><img src="../images/index_r2_c11.jpg" alt="1" name="index_r2_c111" width="62" height="33" border="0" id="index_r2_c111"></a></td>
                    <td><a href="http://www.esferalibros.com/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r2_c141','','images/index_r2_c14_f2.jpg',1)"><img src="../images/index_r2_c14.jpg" alt="1" name="index_r2_c141" width="74" height="33" border="0" id="index_r2_c141"></a></td>
                    <td><a href="http://www.esferallibres.com/" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r2_c181','','images/index_r2_c18_f2.jpg',1)"><img src="../images/index_r2_c18.jpg" alt="1" name="index_r2_c181" width="111" height="33" border="0" id="index_r2_c181"></a></td>
                    <td><img src="../images/spacer.gif" alt="1" width="20" height="20"></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td> </td>
        <td><table width="100%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#FECE46">
          <tr>
            <td><img src="../images/spacer.gif" alt="1" width="34" height="10"></td>
            <td><a href="aesfera.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r3_c51','','../images/index_r3_c5_f2.gif',1)"><img src="../images/index_r3_c5.gif" alt="1" name="index_r3_c51" width="168" height="21" border="0" id="index_r3_c51"></a></td>
            <td><a href="distribuidores.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r3_c91','','../images/index_r3_c9_f2.gif',1)"><img src="../images/index_r3_c9.gif" alt="1" name="index_r3_c91" width="129" height="21" border="0" id="index_r3_c91"></a></td>
            <td><a href="imprensa.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r3_c111','','../images/index_r3_c11_f2.gif',1)"><img src="../images/index_r3_c11.gif" alt="1" name="index_r3_c111" width="89" height="21" border="0" id="index_r3_c111"></a></td>
            <td><a href="avisolegal.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('index_r3_c161','','../images/index_r3_c16_f2.gif',1)"><img src="../images/index_r3_c16.gif" alt="1" name="index_r3_c161" width="116" height="21" border="0" id="index_r3_c161"></a></td>
            <td><img src="../images/spacer.gif" alt="1" width="52" height="10"></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td> </td>
        <td height="24"> </td>
      </tr>
      <tr>
        <td bgcolor="#CC0702"> </td>
        <td height="24"><img src="../images/tit_passatempos.gif" alt="1" width="570" height="34"></td>
      </tr>
      <tr>
        <td> </td>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="30">
          <tr>
            <td><?php 
		if(isset($_GET["e"])){ // Sessao expirou
	unset($_GET["e"]);
//		echo "<script type=\"text/javascript\"> alert(\"A sua sessao expirou.\"); /script>";
	echo "A sua sessao expirou.<br>";
}

if(isset($_GET["reg"])){ // Sessao expirou
	unset($_GET["reg"]);
	echo "Irá receber um email de confirmacao dentro de poucos minutos. Por favor siga as instrucões presentes no email.<br>";
}

if(isset($_GET["regC"])){ // Sessao expirou
	unset($_GET["regC"]);
	echo "Confirmação concluida. Pode efectuar o seu login com os seus dados.<br>";
}


if (isset($_POST["s1"])) {
	if(isset($_POST["login"]) && isset($_POST["password"])){
		$valid = checkLogin($_POST["login"], md5($_POST["password"]));
		if ($valid) {
			$_SESSION["logged"] = true;
			$_SESSION["login"] = $_POST["login"];
			unset($_SESSION["refresh"]);
			header("Location: main.php");
			exit();
		}
	}
}
else if(!isset($_SESSION["refresh"])) {
	$_SESSION["refresh"] = 1;
	echo "<META HTTP-EQUIV='refresh' CONTENT='0'; URL='".$_SERVER['PHP_SELF']."'>";
	exit();
}

if (isset($_POST["aa"])) {
	$altered = alterPass($_POST["old_pass"], $_POST["new_pass"], $_POST["confirm_new"]);

	if ($altered == 1) {
		$_SESSION["alert"] = "A password foi alterada com sucesso!";
		header("Location: main.php");
		exit;
	}
	else if ($altered == -1) {
		$_SESSION["alert"] = "A password não está correcta!";
		header("Location: login.php?a=1");
		exit;
	}
	else if ($altered == -2) {
		$_SESSION["alert"] = "Passwords não coincidem!";
		header("Location: login.php?a=1");
		exit;
	}
}

if (isset($valid) && !$valid)
	echo "<script type=\"text/javascript\"> alert(\"A password não está correcta!\"); </script>";

		if (isset($_SESSION["logged"]) && ($_SESSION["logged"])){
	 if (isset($_GET["a"])) {
		if(isset($_SESSION["time"]) && $_SESSION["time"] < time() - $_SESSION["props"]->get("expire")) { // Verifica se a sessao expirou
			unset($_SESSION["time"]);
	   		header("Location: main.php?l=1");
		}
		else $_SESSION["time"] = time();	

		if (isset($_SESSION["alert"])) {
			echo "<script type=\"text/javascript\"> alert(\"".$_SESSION["alert"]."\"); </script>";
			unset($_SESSION["alert"]);
		}
		echo
			"<form name=\"frm_alter\" action=\"login.php\" method=\"POST\">
			<span class=\"style1\"><strong>Trocar password</strong></span>
<table cellpadding=\"0\" cellspacing=\"5\">
			<tr>
				<td><span class=\"style5\">
	  			  Password actual:					</span></td>
				<td>
					<INPUT name=\"old_pass\" type=\"password\" class=\"style5\"/><br/>					</td>
			</tr>
			<tr>
				<td class=\"style5\">
		  			Password nova:					</td>
				<td>
					<INPUT name=\"new_pass\" type=\"password\" class=\"style5\"/><br/>					</td>
			</tr>
			<tr>
				<td class=\"style5\">
			  		Confirmar nova:					</td>
				<td>
					<INPUT name=\"confirm_new\" type=\"password\" class=\"style5\"/><br/>					</td>
			</tr>
			<tr>
			  <td> </td>
			  <td><input class=style5 type=\"submit\" value=\"Aceitar\" name=\"aa\"/></td>
			  </tr>
			</table>
</form>
			<a href=\"main.php\" class=\"style5\">Voltar</a>
";			
	}
//		else header("Location: main.php");
}		

if (!isset($_GET["a"]))
echo
	"
<span class=\"style1\"><strong>Login</strong></span>
<form name=\"frm_register\" action=\"login.php\" method=\"POST\">
		  <table width=\"300\" border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
              <tr>
                <td class=\"style5\">user</td>
                <td><input name=\"login\" type=\"text\" class=\"style5\" id=\"login\"></td>
              </tr>
              <tr>
                <td class=\"style5\">pass</td>
                <td><input name=\"password\" type=\"password\" class=\"style5\" id=\"password\"></td>
              </tr>
              <tr>
                <td> </td>
                <td><input name=\"s1\" type=\"submit\" class='style5' value=\"aceitar\"></td>
              </tr>
            </table>
</form>
		<a href=\"index.php\" class=\"style5\">Inicio</a>
	";
?></td>
          </tr>
        </table>
        </table>
        <!-- #BeginLibraryItem "/Library/morada.lbi" -->
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="27"> </td>
            <td><DIV class=style5 align=center>© A Esfera dos Livros, Rua Garrett, n,º 19 - 2º A, 1200-203 Lisboa<br>
              Telef: 21 340 40 64 | Fax: 21 340 40 69<br>
              <br>
            </DIV></td>
          </tr>
        </table>
      <!-- #EndLibraryItem --></td>
  </tr>
</table>

 

line 37 is:

?>

line 287 is:

header("Location: main.php");

 

I don't know how to write this page :(

You could use include, thats the way how I do it.

 

You make a page with the header you specificly need at the top and then you let include it your code.

 

Can you explain me a little better?

Theres no other comand that do the same than header() that can be used?

 

I don't think so no,

 

well you basicly make a php file with the headers you want for that specific page at top and then you use include() to include the rest of the code (which is storen in another php file).

 

Tell me what the name of your login page is and the page where you keep the code (to log in)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.