I have 1 problem in my web is this: Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/subdomain/index.php:4) in /home/user/public_html/subdomain/conectar.php on line 22 Code (markup): and the conectar.php <?php session_start(); $_SESSION['Titulo']="title"; $strUsuario=$_REQUEST['usuario']; $strContrasena=$_REQUEST['contrasena']; //echo "Usuario: ".$strUsuario." ".$strContrasena. "<br>"; if(($strUsuario!="")||($strContrasena!="")){ $conn=mysql_connect("localhost","dates","dates"); $bd=mysql_select_db("dates",$conn); $sql = "SELECT id FROM aso WHERE usuario='".$strUsuario."' AND password='".$strContrasena."'"; //echo $sql. "<br>"; $orden_fecha = mysql_query($sql, $conn) or die(mysql_error()); $result = mysql_fetch_assoc($orden_fecha)or die("errores"); $total = mysql_num_rows($result); //echo "total: ".$total. "<br>"; //if($total!=0){ $_SESSION['usuario']=$result['id']; //echo "[".$_SESSION['usuario']. "]"; //} }else{ header("Location: ../index.php"); //<<<<------ line 22 } ?> Code (markup): thanks for the help
I tried the script with apache server and works fine, they redirect me to ../index.php I don't get any errors. Check what do you have in line #4 on index.php. Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/subdomain/index.php:4)
Simply, just put this code: <?php session_start(); $_SESSION['Titulo']="title"; $strUsuario=$_REQUEST['usuario']; $strContrasena=$_REQUEST['contrasena']; //echo "Usuario: ".$strUsuario." ".$strContrasena. "<br>"; if(($strUsuario!="")||($strContrasena!="")){ $conn=mysql_connect("localhost","dates","dates"); $bd=mysql_select_db("dates",$conn); $sql = "SELECT id FROM aso WHERE usuario='".$strUsuario."' AND password='".$strContrasena."'"; //echo $sql. "<br>"; $orden_fecha = mysql_query($sql, $conn) or die(mysql_error()); $result = mysql_fetch_assoc($orden_fecha)or die("errores"); $total = mysql_num_rows($result); //echo "total: ".$total. "<br>"; //if($total!=0){ $_SESSION['usuario']=$result['id']; //echo "[".$_SESSION['usuario']. "]"; //} }else{ echo' <script> location = "../index.php"; </script> '; } ?> PHP:
Are you sure that you don't have any whitespace before the <?php tag? Also, do you have any automatically included libs by your server that may have whitespace outside of the PHP blocks?
Please check your header. Use Location not location & Do not leave any whitespace between header like header("Location:index.php"); not header("location: index.php");
Here is a easy fix: <?php ob_start(); ?> PHP: Just add that before: <?php session_start(); ?> PHP: I hope i helped. Thanks, Michael