jcfr Posted September 17, 2009 at 09:34 AM Report Share #287416 Posted September 17, 2009 at 09:34 AM Boas, implementei um sistema de login numa página que estou a criar, no meu servidor local funciona na perfeição, no entanto quando fiz o upload para o host começou a dar alguns erros embora funcione e cerifique as sessões, mas não me convém que esses erros apareçam. o código é o seguinte: <?php include ("mysqlconnect.php"); //ligar a base de dados mysql_select_db ("$database_TestConnect") or die ("Impossivel ligar a base de dados"); //verificar ligação à tabela $table = "particular"; if (mysql_num_rows(mysql_query ("SHOW TABLES LIKE'".$table."'"))) { //print ("Tabela encontrada, insira os seus dados de registo.<br>"); } else { //print ("A tabela não foi encontrada.<br>"); } ?> <?php //variaveis que recebem os valores de login $user_user = $_POST['user']; $user_pass = $_POST['pass']; $user_type = $_POST['tipo']; $nome_utilizador = $user_user; $tipo_utilizador = $user_type; $pass_utilizador = $user_pass; if($user_type=='*******'){ $check = mysql_query("SELECT * FROM particular WHERE user = '".$_POST['user']."' AND pass = '".$_POST['pass']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=notdados'>"; }else if($check2==1){ session_start("log"); $_SESSION["nome"] = $nome_utilizador; $_SESSION["pass"] = $pass_utilizador; $_SESSION["tipo"] = $user_type; //$_SESSION["cod"] = $cod_util; echo "<meta http-equiv='refresh' content='0.2;URL=../*****/pre_index.php'>"; } }else if($user_type=='*****'){ $check = mysql_query("SELECT * FROM empresas WHERE user = '".$_POST['user']."' AND pass = '".$_POST['pass']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=notdados'>"; }else if($check2==1){ $myrowres = mysql_fetch_array($check); if ($myrowres[12] == 'sim'){ session_start("log"); $_SESSION["nome"] = $nome_utilizador; $_SESSION["pass"] = $pass_utilizador; $_SESSION["tipo"] = $user_type; //$_SESSION["cod"] = $cod_util; echo "<meta http-equiv='refresh' content='0.2;URL=../****/index.php'>"; }else { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=notactiv'>"; } } }else if($user_type=='*****'){ $check = mysql_query("SELECT * FROM adm WHERE user = '".$_POST['user']."' AND pass = '".$_POST['pass']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=notdados'>"; }else if($check2==1){ session_start("log"); $_SESSION["nome"] = $nome_utilizador; $_SESSION["pass"] = $pass_utilizador; $_SESSION["tipo"] = $user_type; //$_SESSION["cod"] = $cod_util; echo "<meta http-equiv='refresh' content='0.2;URL=../*****/index2.php'>"; } }else { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=nottype'>"; } ?> O erro que aparece é o seguinte: "Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\****\login.php:19) in C:\****\login.php on line 42" se alguem me poder explicar porque é que isto acontece agradecia... desde já obrigado por qualquer ajuda que possa chegar. Link to comment Share on other sites More sharing options...
scorch Posted September 17, 2009 at 09:38 AM Report Share #287417 Posted September 17, 2009 at 09:38 AM A função session_start(); tem de estar logo a seguir ao <?php. <?php session_start("log"); include ("mysqlconnect.php"); //ligar a base de dados mysql_select_db ("$database_TestConnect") or die ("Impossivel ligar a base de dados"); //verificar ligação à tabela $table = "particular"; if (mysql_num_rows(mysql_query ("SHOW TABLES LIKE'".$table."'"))) { //print ("Tabela encontrada, insira os seus dados de registo.<br>"); } else { //print ("A tabela não foi encontrada.<br>"); } ?> <?php //variaveis que recebem os valores de login $user_user = $_POST['user']; $user_pass = $_POST['pass']; $user_type = $_POST['tipo']; $nome_utilizador = $user_user; $tipo_utilizador = $user_type; $pass_utilizador = $user_pass; if($user_type=='*******'){ $check = mysql_query("SELECT * FROM particular WHERE user = '".$_POST['user']."' AND pass = '".$_POST['pass']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=notdados'>"; }else if($check2==1){ $_SESSION["nome"] = $nome_utilizador; $_SESSION["pass"] = $pass_utilizador; $_SESSION["tipo"] = $user_type; //$_SESSION["cod"] = $cod_util; echo "<meta http-equiv='refresh' content='0.2;URL=../*****/pre_index.php'>"; } }else if($user_type=='*****'){ $check = mysql_query("SELECT * FROM empresas WHERE user = '".$_POST['user']."' AND pass = '".$_POST['pass']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=notdados'>"; }else if($check2==1){ $myrowres = mysql_fetch_array($check); if ($myrowres[12] == 'sim'){ $_SESSION["nome"] = $nome_utilizador; $_SESSION["pass"] = $pass_utilizador; $_SESSION["tipo"] = $user_type; //$_SESSION["cod"] = $cod_util; echo "<meta http-equiv='refresh' content='0.2;URL=../****/index.php'>"; }else { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=notactiv'>"; } } }else if($user_type=='*****'){ $check = mysql_query("SELECT * FROM adm WHERE user = '".$_POST['user']."' AND pass = '".$_POST['pass']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=notdados'>"; }else if($check2==1){ $_SESSION["nome"] = $nome_utilizador; $_SESSION["pass"] = $pass_utilizador; $_SESSION["tipo"] = $user_type; //$_SESSION["cod"] = $cod_util; echo "<meta http-equiv='refresh' content='0.2;URL=../*****/index2.php'>"; } }else { echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=nottype'>"; } ?> PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum. Link to comment Share on other sites More sharing options...
jcfr Posted September 17, 2009 at 12:19 PM Author Report Share #287435 Posted September 17, 2009 at 12:19 PM obrigado, realmente no login.php deu resultado. no entanto tenho outras páginas em que o erro também aparece: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\*****\index.php:1) in C:\*****\index.php on line 2 uma das páginas é esta: <?php session_start(); if((isset($_SESSION['****']))&&(isset($_SESSION['****']))&&(isset($_SESSION['****']))&&($_SESSION['tipo'])=='******'){ $nome = $_SESSION['nome']; $tipo = $_SESSION['****']; $pass = $_SESSION['pass']; echo "$nome"; echo "$pass"; echo "$tipo"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Empresa</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Cache-Control" content="no-cache" /> <link rel="shortcut icon" href="imagens/icon.jpg" type="image/x-icon" /> <link rel="icon" href="imagens/icon.jpg" type="image/x-icon" /> <link rel="stylesheet" type="text/css" href="css/style.css" /> <script src="Scripts/swfobject_modified.js" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ document.write('<script type="text/javascript" src="http://' + location.hostname + ':8880/javascript/promo-flags.js.php"></' + 'script>\n'); //]]> </script> <style type="text/css"> <!-- body { margin-top:0; background:#FFFFFF; font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif; font-size:small; margin:8px 0 16px; text-align:center; } .appnitro { font-family:Lucida Grande, Tahoma, Arial, Verdana, sans-serif; font-size:small; } .barras { width:136px; font-size:14px; } .barras { width:136px; font-size:14px; } --> </style> </head> <body leftmargin="20px" rightmargin="20px"> <div align="center" id="geral"> <!-- inicio da div onde se coloca a header --> <table align="center" width="90%" cellpadding="0" cellpadding="0" border="0"> <tr> <td width="70%"> <table border="0" width="100%" cellpadding="0" cellpadding="0"> <tr> <td align="left"> <p align="left"><img src="../******/logo.jpg" width="491" height="126" border="0" /></p> </td> </tr> <tr> <td align="center"> </td> </tr> </table> </td> <td width="30%"> Publicidade </td> </tr> </table> <div id="header"> </div> <div align="center" id="menu"> </div> <div id="geral"> <div id="corpo"> <table align="center" width="90%" height="615" border="0" cellspacing="0"> <tr> <td align="left" valign="top" width="16%" height="100%" bgcolor="#B8D00A"> <table cellSpacing="0" cellPadding="0" width="90%" align="center"> <tr style="CURSOR: hand"> <td class="menu_title" id="menuTitle1" background="/******/title_bg_hide.gif" height="25"> <strong> <span>Geral</span></strong></td> </tr> <tr> <td> <div class="sec_menu" id="menuxp1"> <table style="POSITION: relative; TOP: 10px" cellSpacing="0" cellPadding="0" width="100%" align="center"> <tr> <td align="center" width="100%" height="20"> <form style="barras" id="info" action="info.php" target="frame1"> <input style="width:130px" type="submit" value="Informação Geral" /> </form> </td> </tr> <tr> <td align="center" height="20"> <form style="barras" id="addfotos" action="add_fotos.php" target="frame1"> <input style="width:130px" type="submit" value="Adicionar Fotos" /> </form> </td> </tr> <tr> <td align="center" height="20"> <form style="barras" id="mensagens" action="mensagens.php" target="frame1"> <input style="width:130px" type="submit" value="Mensagens" /> </form> </td> </tr> <tr> <td align="center" height="20"> <form style="barras" id="notificar" action="notificar.php" target="frame1"> <input style="width:130px" type="submit" value="Notificações" /> </form> </td> </tr> <tr> <td align="center" height="20"> <form style="barras" id="falar" action="falar.php" target="frame1"> <input style="width:130px" type="submit" value="Fale Connosco" /> </form> </td> </tr> <tr> <td height="20"><!--spacer--></td> </tr> </table> </div> </td> </tr> </table> <table cellSpacing="0" cellPadding="0" width="90%" align="center"> <tr style="CURSOR: hand"> <td class="menu_title" id="menuTitle2" background="/******/title_bg_hide.gif" height="25"><span><strong>Viaturas</strong></span></td> </tr> <tr> <td> <div class="sec_menu" id="menuxp2"> <table style="POSITION: relative; TOP: 10px" cellSpacing="0" cellPadding="0" width="100%" align="center"> <tr> <td align="center" height="20"> <form style="barras" id="listar" action="listar.php" target="frame1"> <input style="width:130px" type="submit" value="Listar Stock" /> </form> </td> </tr> <tr> <td align="center" height="20"> <form style="barras" id="expiradas" action="expiradas.php" target="frame1"> <input style="width:130px" type="submit" value="Expiradas" /> </form> </td> </tr> <tr> <td align="center" height="20"> <form style="barras" id="adicionar" action="add.php" target="frame1"> <input style="width:130px" type="submit" value="Adicionar" /> </form> </td> </tr> <tr> <td height="20"><!--spacer--></td> </tr> </table> </div> </td> </tr> </table> <table cellSpacing="0" cellPadding="0" width="90%" align="center"> <tr style="CURSOR: hand"> <td class="menu_title" id="menuTitle3" background="/******/title_bg_hide.gif" height="25"><span><strong>Estatísticas</strong></span> </td> </tr> <tr> <td> <div class="sec_menu" id="menuxp3"> <table style="POSITION: relative; TOP: 10px" cellSpacing="0" cellPadding="0" width="100%" align="center"> <tr> <td align="center" height="20"> <form style="barras" id="consultas" action="consultas.php" target="frame1"> <input style="width:130px" type="submit" value="Consultas" /> </form> </td> </tr> <tr> <td height="20"><!--spacer--></td> </tr> </table> </div> </td> </tr> </table> <table cellSpacing="0" cellPadding="0" width="80%" align="center"> <tr style="CURSOR: hand"> <td class="menu_title" background="/******/bg_quit.gif" height="25"> <form id="sair" action="../index.php"> <input type="submit" value="Sair" /> </form> </td> </tr> </table> </td> <td width="84%" height="615" bgcolor="#CCCCCC"> <iframe frameborder="0" vspace="0" id="frame1" name="frame1" width="100%" height="100%" scrolling="auto"> </iframe> </td> </tr> </table> </div> </div> <?php echo("<script language=\"javascript\">"); echo("frame1.location.href = \"info.php\";"); echo("</script>"); ?> <?php } else if(($_SESSION['tipo'])=='******'){ session_destroy(); echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=errado'>"; }else{ session_destroy(); echo "<meta http-equiv='refresh' content='0.2;URL=../index2.php?notok=log'>"; } ?> </body> </html> não percebo qual é o problema, desta vez o session_start() está logo no inicio... se alguem me poder responder agradecia Link to comment Share on other sites More sharing options...
yoda Posted September 17, 2009 at 12:29 PM Report Share #287438 Posted September 17, 2009 at 12:29 PM Limpa espaços e tabs desnecessários das primeiras 3 linhas before you post, what have you tried? - http://filipematias.info sense, purpose, direction Link to comment Share on other sites More sharing options...
infopc Posted September 17, 2009 at 12:38 PM Report Share #287443 Posted September 17, 2009 at 12:38 PM session_start() tem mesmo que ser o primeiro código depois do <?php um espaço só antes de session_start() ou depois de <?php chega para não funcionar Fica bem O que não tem solução, solucionado esta... Link to comment Share on other sites More sharing options...
jcfr Posted September 17, 2009 at 12:48 PM Author Report Share #287444 Posted September 17, 2009 at 12:48 PM muito obrigado, o erro era um espaço antes de <?php agradeço a todos os que me ajudaram qualquer duvida coloco aqui no melhor forum do genero que conheço, vou vendo alguns tópicos algo que eu saiba responder tentarei fazê-lo, ainda sou noob nisto mas ja aprendi qualquer coisa... mais uma vez obrigado Link to comment Share on other sites More sharing options...
softklin Posted September 17, 2009 at 01:03 PM Report Share #287449 Posted September 17, 2009 at 01:03 PM Um problema bastante típico, um espaço antes do <?php. Para referência, o importante é que não haja espaços antes da tag de abertura do PHP, porque dentro da zona delimitada por <?php e ?> podem colocar os espaços e parágrafos que quiserem, visto que o PHP irá por si remover/não vai ligar a isso na altura de ler o ficheiro. Como nota final, esse problema tem a ver com os headers de HTTP, que por haver um output para o browser (o tal espaço), ele é forçado a enviar o documento, já com os respectivos cabeçalhos. Nick antigo: softclean | Tens um projeto? | Wiki P@P Ajuda a comunidade! Se encontrares algo de errado, usa a opção "Denunciar" por baixo de cada post. Link to comment Share on other sites More sharing options...
jcfr Posted September 17, 2009 at 01:23 PM Author Report Share #287452 Posted September 17, 2009 at 01:23 PM muito obrigado, ainda ando a aprender e o forum tem ajudado emenso, até agora tinha encontrado sempre as respostas aos meus problemas em topicos ja criados (embora tivesse de adaptar a solução ao meu caso, mas é mesmo para isso que servem as soluções para serem gerais e cada um usar como precisa), desta vez é que tive de criar um topico porque não encontrei a resposta, obrigado por toda a ajuda e esclarecimentos.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now