php: about open new web page [duplicate] - php

This question already has answers here:
Warning: Cannot modify header information - headers already sent by [closed]
(3 answers)
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
I want open new web page to display the image,when my php was create the image
<?
.........
$img = $file.create_image; // $img like http://abc.com/abc.jpg
header("Location: $img");
?>
when i using header, it have a error
Cannot modify header information - headers already sent by (output....
or using other php function to open new page.

The headers needs to be written before any other content, this means you have to remove any white spaces/empty lines at the top of your document. You have to make sure that any HTML or echo statements is executed AFTER your header statement.

if you're using session in this page then write
ob_start(); on top of page (1st line)

Related

Session Start Error [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
"Cannot send session cache limiter - headers already sent" [duplicate]
(1 answer)
Closed 8 years ago.
I know this has been posted before but none of the other answers worked for me. Here is my problem: I am making a login page for my website. I keep getting this error and I cant get rid of it:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/howto570/public_html/admin/index.php:1) in /home/howto570/public_html/admin/index.php on line 6
now here is the first bit of code
<?php
$session_prefix = "henry_";
$default_title = "Admin Panel";
$folder_root = "/admin";
session_start();
require("../auth.php");
$userdata = array();
?>
Even when I slash out all the other code like so:
<?php
session_start();
//$session_prefix = "henry_";
//$default_title = "Admin Panel";
//$folder_root = "/admin";
//require("../auth.php");
//$userdata = array();
?>
I still get the error.
So im at a loss not sure what to do, you can see the site itself here: www.howtotech.ca/admin/ . I dont know what to do.
From looking at your link, it looks like you are probably including this script in another script. There is HTML being outputted before your error message (ie. the head section). You can fix this by moving the session_start() to the top of the script that is including your script.
This mostly happens because something is outputted before the session_start(). Even if you have single space before the starting of php remove it, the session_start should come before any output. If this doesn't work than most probably your editor can't see the blank space so you have to create a new file and paste the content in it.
<?php
^^^^
session_start();
?>
Hope this helps you

Having trouble with php code to redirect [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 8 years ago.
I am a beginner in php..
I need to redirect from one php file to another php file..
I used this code for this.
header("Location: stu_rep.html");
but it shows this error..
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\auttvl\admin\stu_rep_view.php:241) in C:\xampp\htdocs\auttvl\admin\stu_rep_view.php on line 492
I need to know what is wrong,Is there any other way to redirect without using header?
Thanks!
Header(); sends a HTTP header. But HTTP headers can only be sent before anything else. In your case, you are probably printing something out before using header();. Remove the printings and your done.
More informations here:
http://www.php.net/manual/de/function.header.php
Headers must be sent before any output is generated on the website. To "work around" this, you can add ob_start(); to the top of your file.

Cannot modify header information [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
my site works well in localhost (everything works fine)
but when I upload it in web and try to redirect the page after updating the data it says -> Cannot modify header information
95% you are trying to set a cookie, mime-type or redirection (short: http header) after you have sent http body, i.e. content. Check if you you have anything including whitespaces outside the php delimeters.
If you use the header function you have to be careful... You can't send any header before the "header location".
ob_start('mypage');
<html>
// Your code ...
</html>
ob_end_flush();
What's the error ? (php.ini, active the errors)
Else you can use the ob_start() function !

Getting Session error on live site [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
I have started my session in config.php file & i have included that file on every page on my site,
my site works fine in localhost,
but when i have done live to it,it shows error like this,
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
Any suggestions...
Thanks,
check that you don't send content before calling session_start. Just make session_start the first thing you do in your PHP file.
<?php session_start(); ?>
If you will have space after closing PHP Tags in your config.php at the end of your code then also these warning will come.
So make sure you don't have any space after closing of PHP Tags which is ?>

Inserting PHP script using include(''); causes headers already sent error [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
I am trying to insert a form script into my home page index.php by using the following line of code.
<?php include('email-system/index.php'); ?>
and continue to get the two error messages below. The form shows up, but I get this error below quite often when trying to insert script into my home page using the include statement. I have read in a number of different places that it could be white space. Since the file works fine if you go to www.mysite.com/email-system/index.php I'm assuming that it's not white space. Any ideas on what my problem is and how I could insert the code and correct the errors? Thank you in advance.
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/84/8661784/html/header.php:7) in /home/content/84/8661784/html/email-system/index.php on line 6
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/84/8661784/html/header.php:7) in /home/content/84/8661784/html/email-system/index.php on line 6
You will only get that if you are echoing output before the include statement.
Make sure whatever you need is included / loaded before you send output to the user.

Categories