tags:

views:

59

answers:

5
                session_start(); 
   $_SESSION['fname']=$row['fname'];
  $_SESSION['user']=$row['name'];
  $_SESSION['adpoint'] = $row['adpoint'];
  $_SESSION['phone']=$row['phone'];
  $_SESSION['id'] = $row['id'];
  $_SESSION['rememberMe'] = $_POST['rememberMe'];

  // Store some data in the session

  setcookie('smsapp',$_POST['rememberMe']);
  echo "your name"." ".$_SESSION['user'];

  Print_r ($_SESSION);
 header("Location: http://www.niktrixhosting.com/login/user/index.php");

here in this code header("Location: http://www.niktrixhosting.com/login/user/index.php"); this line is not redirecting it

plz mentionif any another function for redirecting page .

+2  A: 

You're trying to set the headers after sending them. Comment out the echo "your name"." ".$_SESSION['user']; line and everything will work.

Explanation: The headers are always the first thing sent (that's why they're called headers). When you call echo, part of the page is sent, but if the headers aren't set, they will be sent first. What's happening in your code is that the echo line is sending the headers, and then you're trying to set them after the headers have already been sent (which doesn't work).

Brendan Long
yah its working after removing echo before header
nicky
+4  A: 

You can't echo and print_r or give any other output before function header.

lfx
+2  A: 

Headers should be sent before any output, so any statement with an echo or a print_r before a header will cause errors.

Ygam
A: 

try

echo "<script>window.location=\"http://www.niktrixhosting.com/login/user/index.php\"&lt;/script&gt;";

instead of:

header("Location: http://www.niktrixhosting.com/login/user/index.php");
Treby
Why use Javascript when they can just fix the error?
Brendan Long
So that what he wants to happen works. even if he echo or display something before redirecting
Treby
@terby thank i was searching for alternate to this only.
nicky
@nicky, this is not a good solution. You're now not redirecting anyone who doesn't have Javascript, your redirect will go slower, and there's no reason to `echo` before a redirect anyway. Why print to a page that shouldn't even be displayed?
Brendan Long
A: 

you are not to echo/print out/output anything before using header(). that will really affect your PHP page.

trace