2

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!

user3763227
  • 292
  • 2
  • 15

2 Answers2

1

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

Xatenev
  • 6,383
  • 3
  • 18
  • 42
  • thanks got the output.. I have both html and php in a Single php file so i confused – user3763227 Jun 25 '14 at 07:44
  • You shouldn't put both into one file. Put your html into templates, so they are seperated from the PHP code. You always should have logic(PHP) and design(HTML/CSS) seperated. – Xatenev Jun 25 '14 at 07:45
0

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.

CmdrSharp
  • 1,085
  • 13
  • 30