-5

I created a web site, with php and SQL using WampServer. And after a condition or in boucle I use Header location to transfer the user to another page. But I got an error from the server, I think is because I use the header after a code and not in . I deleted all blank spaces.

if($passfinal['contrasena']==$_POST['password'])
{
$_SESSION['logedin']=TRUE;
$_SESSION['userid']=$passfinal['id'];
header('Location: ../index.php');
}

Do you have something to help me? Thnak you.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • 1
    Put an `exit;` behind `header(...)`. Which error message do you get? – djot Sep 23 '13 at 00:13
  • check the error file to find the issue, it may be an error or you output some data. – mbouzahir Sep 23 '13 at 00:15
  • The problem still. I got this error:Warning: Cannot modify header information - headers already sent by (output started at /home/sirobdco/public_html/login/login.php:11) in /home/sirobdco/public_html/login/includes/loginform/loginform.php on line 37 – Boris Detry Sep 23 '13 at 00:16
  • ok what do you have in /home/sirobdco/public_html/login/login.php line 11? – mbouzahir Sep 23 '13 at 00:18
  • I have this, just another HTML line: – Boris Detry Sep 23 '13 at 00:21
  • than you need to read about how location works http://php.net/manual/en/function.header.php must be called before any actual output is sent move your condition before that output – mbouzahir Sep 23 '13 at 00:25

2 Answers2

0

I think, here is problem $_POST['password'], because before you make compare, first you must check if(isset($_POST['password'])), blank spaces isn't important in this case and last one: I advise you, that you must write full url in header function, like this: header('location: http://example.com/index.php'), because this is more nice and true way.

dasdasdasdasd
  • 1,249
  • 2
  • 11
  • 13
0

Warning: Cannot modify header information - headers already sent by (output started at /home/sirobdco/public_html/login/login.php:11) in /home/sirobdco/public_html/login/includes/loginform/loginform.php on line 37

You already sent headers so PHP cannot send them again!
That is, before your code

header('Location: ../index.php');

You already send headers - blank space in html, an echo in PHP, etc.

Have a read through this:
http://php.net/manual/en/function.header.php

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

James
  • 4,644
  • 5
  • 37
  • 48