Jump to content

Erro redireccionamento


PF2G

Recommended Posts

Boas, eu estou a tentar fazer com que o utilizador entre na página user.php se tiver logado, apenas.

Mas está-me a dar erro no header:

Warning: Cannot modify header information - headers already sent by (output started at /home4/dreamcli/public_html/infocar/top.php:18) in /home4/dreamcli/public_html/infocar/user.php on line 462

user.php:

<?php
include ('top.php');
if (isset($_SESSION['username'])){
if (isset($_POST['submit'])){
 $nome=$_POST['nome'];
 $morada=$_POST['morada'];
 $cp1=$_POST['cp1'];
 $cp2=$_POST['cp2'];
 $cp=$cp1.'-'.$cp2;
 $localidade=$_POST['localidade'];
 $data_nascimento=$_POST['data_nascimento'];
 $bi_cc=$_POST['bi_cc'];
 $val_bi_cc=$_POST['val_bi_cc'];
 $nif=$_POST['nif'];
 $email=$_POST['email'];
 $tele=$_POST['tele'];
 $update_user="UPDATE civil_users
 SET nome_user='$nome', morada_user='$morada', cod_postal_user='$cp', localidade_user='$localidade', data_nasc_user='$data_nascimento',
 bi_cc='$bi_cc', val_bi_cc='$val_bi_cc', nif_user='$nif', email_user='$email', tel_user='$tele'
 WHERE nif_user='".$_SESSION['username']."'";
 $update=mysql_query($update_user, $connect) or die(mysql_error());
 if (!$update){
  echo 'Erro na atualização dos dados.';
 }
 if (mysql_affected_rows($connect) == 1)
 {
  echo '<div class="update_success"> Os seus dados foram alterados com sucesso. </div>';
 }
 else
 {
  echo '<div class="update_error">Não foi possível alterar os seus dados devido a um problema do sistema. Tente mais tarde.</div>';
 }
}
?>

 <div id="menu_side">

  <div id="menu_top">

   <div id="home" style="float: left;">
    <a href="index.php">Home</a>
   </div>

   <div id="whoworks" style="float: left; margin-left: 20px;">
    <a href="whoworks.php">Quem trabalha?</a>
   </div>

   <div id="login" style="float: left; margin-left: 20px;">
    <a style="color: #0066FF;" href="<?php
    if (isset($_SESSION['username'])){
	 echo 'user.php';
    }
    else{
	 echo 'login.php';
    }?>">LOGIN</a>
   </div>

   <div id="faqs" style="float: left; margin-left: 20px;">
    <a href="faqs.php">FAQ's</a>
   </div>

   <div id="suport" style="float: left; margin-left: 20px;">
    <a href="suporte.php">Suporte</a>
   </div>

  </div>

 </div>

   </div>

  </div>

 </div>

 <div id="wraper">

  <div id="wraper_container">

   <div id="user_menu">

 <div id="option">
  <div id="pic" style="float: left; width: 40px; height: 40px; margin-left: 10px; margin-top: 4px;">
   <img src="images/button_save.png" width="100%" height="100%">
  </div>
  <div id="option_text">
   <span>OPÇÃO 1</span>
  </div>
 </div>

 <div id="option">
  <div id="pic" style="float: left; width: 40px; height: 40px; margin-left: 10px; margin-top: 4px;">
   <img src="images/button_save.png" width="100%" height="100%">
  </div>
  <div id="option_text">
   <span>OPÇÃO 2</span>
  </div>
 </div>

 <div id="option">
  <div id="pic" style="float: left; width: 40px; height: 40px; margin-left: 10px; margin-top: 4px;">
   <img src="images/button_save.png" width="100%" height="100%">
  </div>
  <div id="option_text">
   <span>OPÇÃO 3</span>
  </div>
 </div>

 <div id="option">
  <div id="pic" style="float: left; width: 40px; height: 40px; margin-left: 10px; margin-top: 4px;">
   <img src="images/button_save.png" width="100%" height="100%">
  </div>
  <div id="option_text">
   <span>OPÇÃO 4</span>
  </div>
 </div>

 <div id="option">
  <div id="pic" style="float: left; width: 40px; height: 40px; margin-left: 10px; margin-top: 4px;">
   <img src="images/button_save.png" width="100%" height="100%">
  </div>
  <div id="option_text">
   <span>OPÇÃO 5</span>
  </div>
 </div>

 <div id="option">
  <div id="pic" style="float: left; width: 40px; height: 40px; margin-left: 10px; margin-top: 4px;">
   <img src="images/button_save.png" width="100%" height="100%">
  </div>
  <div id="option_text">
   <span>OPÇÃO 6</span>
  </div>
 </div>

 <div id="option">
  <div id="pic" style="float: left; width: 40px; height: 40px; margin-left: 10px; margin-top: 4px;">
   <img src="images/button_save.png" width="100%" height="100%">
  </div>
  <div id="option_text">
   <span>OPÇÃO 7</span>
  </div>
 </div>

   </div>
   <?php
 $select_user="SELECT * FROM civil_users WHERE nif_user='".$_SESSION['username']."'";
 $query_user=mysql_query($select_user, $connect) or die(mysql_error());
 $user_info=mysql_fetch_assoc($query_user);
   ?>
   <div id="form_user">
 <form method="POST" action="" onsubmit="return checkdate(this.data_nascimento)">
  <table>
   <tr>
    <td align="left">
	 Nome:
    </td>

    <td width="10px"></td>

    <td>
	 <input class="input" type="text" name="nome" value="<?php echo $user_info['nome_user']; ?>"/>
    </td>
   </tr>

   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 Morada:
    </td>

    <td></td>

    <td>
	 <input class="input" type="text" name="morada" value="<?php echo $user_info['morada_user']; ?>"/>
    </td>
   </tr>

   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 Código-Postal:
    </td>

    <td></td>
    <?php
	 if ($user_info['cod_postal_user']!=0){
	 $cp=$user_info['cod_postal_user'];

	 $array=explode('-', $cp, 2);
    ?>
    <td>
	 <input class="input_cp" type="text" name="cp1" maxlength="4" value="<?php echo $array[0] ?>" />
	 -
	 <input class="input_cp1" type="text" name="cp2" maxlength="3" value="<?php echo $array[1] ?>" />
    </td>
   </tr>
    <?php
	 }
	 else{
    ?>
    <td>
	 <input class="input_cp" type="text" name="cp1" maxlength="4" />
	 -
	 <input class="input_cp1" type="text" name="cp2" maxlength="3" />
    </td>
   </tr>
    <?php
	 }
    ?>
   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 Localidade:
    </td>

    <td></td>

    <td>
	 <input class="input" type="text" name="localidade"  value="<?php echo $user_info['localidade_user'] ?>" />
    </td>
   </tr>

   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 Data de Nascimento:
    </td>

    <td></td>

    <td>
	 <input class="input_dn" type="text" value="<?php echo $user_info['data_nasc_user'] ?>" name="data_nascimento" maxlength="10" onkeyup="Formatadata(this,event)" onkeypress="return isNumberKey(event)"/>
	  (DD/MM/AAAA)
    </td>
   </tr>

   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 B.I/C.C:
    </td>

    <td></td>

    <td>
	 <input class="input" type="text" name="bi_cc" value="<?php echo $user_info['bi_cc'] ?>" />
    </td>
   </tr>

   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 Validade B.I/C.C:
    </td>

    <td></td>

    <td>
	 <input class="input" type="text" name="val_bi_cc" value="<?php echo $user_info['val_bi_cc'] ?>" maxlength="10" onkeyup="Formatadata(this,event)" onkeypress="return isNumberKey(event)"/>
    </td>
   </tr>

   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 NIF:
    </td>

    <td></td>

    <td>
	 <input class="input" type="text" name="nif" value="<?php echo $user_info['nif_user'] ?>" />
    </td>
   </tr>

   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 Foto:
    </td>

    <td></td>

    <td>
	 <input class="input_file" type="file" name="foto" />
    </td>
   </tr>

   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 E-Mail:
    </td>

    <td></td>

    <td>
	 <input class="input" type="text" name="email" value="<?php echo $user_info['email_user'] ?>" />
    </td>
   </tr>

   <tr height="10px"></tr>

   <tr>
    <td align="left">
	 Telemóvel/Telefone:
    </td>

    <td></td>

    <td>
	 <input class="input" type="text" name="tele" value="<?php echo $user_info['tel_user'] ?>" maxlength="9" />
	 <br /><br />
	 <input class="button_update" type="submit" name="submit" value="Submeter"/>
    </td>
   </tr>
  </table>
 </form>
   </div>

  </div>

 </div>

 <div id="footer" style="">

  <div id="footer_container">

   <div id="footer_box_zone">

 <div id="footer_box1">

  <div id="f_title">
   Who works?
  </div>

  <div id="f_text_blue">
   TextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemplo
  </div>

  <div id="f_text_gray">
   TextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemplo
  </div>

  <div id="f_readmore">
   <a href="#">+ READ MORE</a>
  </div>

 </div>

 <div id="footer_box2">

  <div id="f_title">
   Features
  </div>

  <div id="feat">
   <div id="txt">
    <span id="num">01.</span>TextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExem
   </div>
  </div>

  <div id="feat">
   <div id="txt">
    <span id="num">02.</span>TextoExemploTextoExemploTextoExemploTextoExemplo
   </div>
  </div>

  <div id="feat">
   <div id="txt">
    <span id="num">03.</span>TextoExemploTextoExemplo
   </div>
  </div>

  <div id="feat">
   <div id="txt">
    <span id="num">04.</span>TextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemplo
   </div>
  </div>

  <div id="feat">
   <div id="txt">
    <span id="num">05.</span>TextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemploTextoExemplo
   </div>
  </div>



  <div id="f_readmore">
   <a href="#">+ READ MORE</a>
  </div>

 </div>

 <div id="footer_box3">
  <img src="images/contact_map.png" width="280" height="230">

  <div id="contact">

   <div id="contact_number" style="">
    telf: 221234567  /  +(351)912345678
   </div>

   <div id="contact_place">
    Rua do Cunha nº144
   </div>

  </div>

 </div>

   </div>


  </div>

  <div id="footer_bottom">

   <div id="fb_leftside">

 <div style="float: left;">
  2012/2013
 </div>

 <div style="float: left; margin-left: 40px;">
  infocar
 </div>

   </div>

   <div id="fb_rightside">
 blablabla
   </div>

  </div>

 </div>

</body>

</html>
<?php
}
else{
 header('Location: login.php');
}
?>

top.php: (ate linha 17)

<?php
   ini_set("session.gc_maxlifetime","2592000"); // 24*30 hours
   session_set_cookie_params( 86400*30 );

   session_start();

   include ('require/db_connect.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
       <title>infoCAR</title>

       <link rel="stylesheet" type="text/css" href="style.css" />

       <!--SCROLL BAR--><link href="jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />
       <link href="jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />
<!-------------VERTICAL-TABS----------------->
Link to comment
Share on other sites

http://php.net/manual/en/function.header.php

header() is used to send a raw HTTP header. See the » HTTP/1.1 specification for more information on HTTP headers.

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

output started at /home4/dreamcli/public_html/infocar/top.php:18

no script top.php (linha 18) é que mandas coisas para o browser antes de tempo.

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Link to comment
Share on other sites

isto tudo é output antes da chamada da função header

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
       <title>infoCAR</title>

       <link rel="stylesheet" type="text/css" href="style.css" />

       <!--SCROLL BAR--><link href="jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />
       <link href="jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />
<!-------------VERTICAL-TABS----------------->
IRC : sim, é algo que ainda existe >> #p@p
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
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.