1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Warning: Cannot modify header information - headers already sent by

Discussion in 'PHP' started by neto, Apr 26, 2007.

  1. #1
    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
     
    neto, Apr 26, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    http://www.php.net/header
     
    nico_swd, Apr 26, 2007 IP
  3. pachecus

    pachecus Well-Known Member

    Messages:
    1,841
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    110
    #3
    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)
     
    pachecus, Apr 26, 2007 IP
  4. AleckProg

    AleckProg Guest

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #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:
     
    AleckProg, Apr 26, 2007 IP
  5. Adam A Flynn

    Adam A Flynn Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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?
     
    Adam A Flynn, Apr 27, 2007 IP
  6. Backlinkshub

    Backlinkshub Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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");
     
    Backlinkshub, Feb 8, 2011 IP
  7. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    try not closing your php file

    remove this

    ?>
     
    srisen2, Feb 8, 2011 IP
  8. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Here is a easy fix:

    
    
    <?php
    
     ob_start();
    
    ?>
    
    
    PHP:
    Just add that before:

    
    
    <?php
    
     session_start();
    
    ?>
    
    
    PHP:
    I hope i helped.

    Thanks,

    Michael
     
    CPAPubMichael, Feb 9, 2011 IP
  9. chintakdholakia

    chintakdholakia Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It worked... Thanks a lot :)
     
    chintakdholakia, Dec 7, 2011 IP