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,213
  • 7
  • 30
  • 49
Lilly Shk
  • 147
  • 1
  • 20

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
  • 31,770
  • 15
  • 58
  • 79