Jump to content

output from session_start


Gurzi

Recommended Posts

Hello, i have a weird doubt and i dont know the answer.

 

I was using the session_start in the first line of my code, and 5 lines after i had to use the header() function and of course it said that ouput already had been sent.

 

I understood and i tried something, like this

 

session_start()

session_destroy()

header()

 

and it worked, and i dont know why , doesn't it sent ouput to the browser ??

 

Weird :s

 

 

Link to comment
https://forums.phpfreaks.com/topic/113271-output-from-session_start/
Share on other sites

I was trying to develop an captcha system so i had this

 

<?php

session_start();

if($_POST['captcha'] != $_SESSION['captcha']){

  header("Location: index.php");

}else{

// do something

}

?>

 

When the user entered the captcha wrong, it says that output already had been sent.

 

So i tried this way:

 

<?php

session_start();

$test = $_SESSION['captcha'];

session_destroy();

 

if($test != $_POST['captcha']){

header("Location: index.php");

}else{

// do something

}

 

?>

 

and it worked :S but i dont know the reason :x

session_start() will register internal output handler for URL rewriting when trans-sid is enabled. If a user uses ob_gzhandler or like with ob_start(), the order of output handler is important for proper output. For example, user must register ob_gzhandler before session start.

 

 

Ok, i'm not sure if it said headers or just output already sent, but in the session_start function description, it says that i throws output

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.