0

I have a page index.php where user enters name and this name is passed in session to negative.php . On loading negative.php it performs few calculations and displays the data. when i directly run negative.php (with session as null value) i want to redirect it to index.php.

This is my code: negative.php:

$(document).ready(function() 
{
.....
.....
}

$name=$_SESSION['name'];
 if($name=="")
{header("Refresh:0;url='http://lilly.co.in/index.php'");}

its giving error as:

Unknown error type: [2] Cannot modify header information - headers already sent by (output started at /mnt/drive2/homeb/home/lilly/www/negativ.php:421)

In my line 421 i have only <?php

Please help

Saty
  • 22,443
  • 7
  • 33
  • 51
Lilly Shk
  • 147
  • 1
  • 21

1 Answers1

0

top of the page start session

<?php
    session_start();
?>

To Check session is empty

if(empty($_SESSION['name']))
{
    header('Location: http://lilly.co.in');
}

Note: Make sure Session has set already with the ('name')

and Possible duplicate of How to fix “Headers already sent” error in PHP

Community
  • 1
  • 1
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85