Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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