header location not working in my php code - php

i have this code,why my header location not working?
its a form of updating and editing and deleting some pages in my control panel...and i have an index.php file in the same folder of form.php...any help please?()i tryed to put the header after the editing and deleting...and still go to the form page not the index...
<?php
include "../../includes/site_includes.php";
//send
if ((isset($_POST["send"])) && ($_POST["send"] == 1)) {
$pageid = $_POST["page_id"];
$pagetitle = $_POST["page_title"];
$nameinmenu = $_POST["page_menu_name"];
$nameinurl = $_POST["page_name_url"];
$link = $_POST["page_link"];
$picture = $_POST["page_pic"];
$desc = $_POST["page_desc"];
$content = $_POST["page_content"];
}
if ((isset($_POST["act"])) && ($_POST["act"] == "add")) {
$sql = insertpage();
if ($result = $mysqli->prepare($sql)) {
$result->bind_param("sssssss", $pagetitle, $nameinmenu, $nameinurl, $link, $picture, $desc, $content);
$result->execute();
$result->store_result();
$rows = $result->num_rows;
}
}
////edit
if ((isset($_GET["act"])) && ($_GET["act"] == "edit")) {
$sql = getfrompages();
if ($result = $mysqli->prepare($sql)) {
$rekza = $_GET["id"];
$result->bind_param("i", $rekza);
$result->execute();
$result->store_result();
$rowsZ = $result->num_rows;
}
if ($rowsZ > 0) {
$row = fetch($result);
$pageid = $row[0]["page_id"];
$pagetitle = $row[0]["page_title"];
$nameinmenu = $row[0]["page_menu_name"];
$nameinurl = $row[0]["page_name_url"];
$link = $row[0]["page_link"];
$picture = $row[0]["page_pic"];
$desc = $row[0]["page_desc"];
$content = $row[0]["page_content"];
}
}
if ((isset($_GET["act"])) && ($_GET["act"] == "delete")) {
$thedelid = $_GET["id"];
$sql2 = delpage();
if ($result2 = $mysqli->prepare($sql2)) {
$result2->bind_param("i", $thedelid);
$result2->execute();
$result2->store_result();
$rowsZ2 = $result2->num_rows;
}
}
header('location: index.php');
exit();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> pages add </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<form method="post" action="">
<table>
<tr>
<td style="font-weight:bold;">title</td>
<td><input type="text" name="page_title" value="<?=$pagetitle?>" /></td>
</tr>
<tr>
<td style="font-weight:bold;">name in menu</td>
<td><input type="text" name="page_menu_name" value="<?=$nameinmenu?>" /></td>
</tr>
<tr>
<td style="font-weight:bold;">name in url</td>
<td><input type="text" name="page_name_url" value="<?=$nameinurl?>" /></td>
</tr>
<tr>
<td style="font-weight:bold;">link</td>
<td><input type="text" name="page_link" value="<?=$link?>" /></td>
</tr>
<tr>
<td style="font-weight:bold;">picture</td>
<td><input type="text" name="page_pic" value="<?=$picture?>" /></td>
</tr>
<tr>
<td style="font-weight:bold;">description</td>
<td><textarea name="page_desc"><?=$desc?></textarea></td>
</tr>
<tr>
<td style="font-weight:bold;">content</td>
<td><textarea name="page_content"><?=$content?></textarea></td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="send" value="1" />
<input type="hidden" name="act" value="<?=$_GET["act"]?>" />
<input type="hidden" name="page_id" value="<?=$pageid?>" />
<input type="submit" value="add" /></td>
</tr>
</table>
</form>
</body>
</html>
solved:
with # Mihai Iorga code i added ob_start();

That is because you have an output:
?>
<?php
results in blank line output.
header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP
Combine all your PHP codes and make sure you don't have any spaces at the beginning of the file.
also after header('location: index.php'); add exit(); if you have any other scripts bellow.
Also move your redirect header after the last if.
If there is content, then you can also redirect by injecting javascript:
<?php
echo "<script>window.location.href='target.php';</script>";
exit;
?>

Try adding ob_start(); at the top of the code i.e. before the include statement.

just use ob_start(); before include function it will help

Remove Space
Correct : header("Location: home.php"); or header("Location:home.php");
Incorrect : header("Location :home.php");
Remove space between Location and : --> header("Location(remove space): home.php");

The function ob_start() will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. So browser will not receive any output and the header will work.Also we should make sure that header() is used on the top of the code.

ob_start();
should be added in the line 1 itself.
like in below example
<?php
ob_start(); // needs to be added here
?>
<!DOCTYPE html>
<html lang="en">
// your code goes here
</html>
<?php
if(isset($_POST['submit']))
{
//code to save data in db goes here
}
header('location:index.php?msg=sav');
?>
adding it below html also doesnt work. like below
<!DOCTYPE html>
<html lang="en">
// your code goes here
</html>
<?php
ob_start(); // it doesnt work even if you add here
if(isset($_POST['submit']))
{
//code to save data in db goes here
}
header('location:index.php?msg=sav');
?>

I use following code and it works fine for me.
if(!isset($_SESSION['user'])) {
ob_start();
header("Location: https://sitename.com/login.php");
exit();
} else {
// my further code
}

I had same application on my localhost and on a shared server. On my localhost the redirects worked fine while on this shared server didn't. I checked the phpinfo and I saw what caused this:
While on my localhost I had this:
So I asked the system admin to increase that value and after he did that, everything worked fine.

for me just add ob_start(); at the start of the file.

It took me some time to figure this out: My php-file was encoded in UTF-8. And the BOM prevented header location to work properly. In Notepad++ I set the file encoding to "UTF-8 without BOM" and the problem was gone.

Check if below are enabled
bz, mbstring, intl, ioncube_loader and Json extension.

It should be Location not location:
header('Location: index.php');

In my case i created new config file with function 'ob_start()' and added this to my .gitignore file.

I use this
header("Location:comments.php");
And it solve out..

In your HTML code, you are using a form and setting action to "", which I understand takes precedence over a header within the form.
I found rather using the action element within the form instead of header Location is one option. I assume you want different options on the link, thus the variable.
<?php $nextLink = "index.php"; ?>
<form method="post" action="<?php echo $nextLink; ?>">
I suggest placing the variable outside a $_POST to start testing with.

In my case, it was extra spaces after ?>
Removed the spaces, and voila it worked.

in my case i just added ob_start(); before include anything and it worked !

Create config.php and put the code it will work

Related

php script is printed not executed

I have following html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fancy Website</title>
</head>
<body>
<div id="content_login">
<form method="post" action="app.php">
<table>
<thead>Please Login for more fancy Content!</thead>
<tr>
<td>Username</td>
</tr>
<tr>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td><input type="submit" name="login" value="Login"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
And this is my php script:
<?php
if(isset($_POST['login'])) {
echo "Hello " . $_GET["username"];
}
?>
Yeah simply nothing, but I only wanted to test, if a script would work when the Login Button is pressed. Surprise: It's not. I open index.html in my browser and the html part works properly, but if I press the Login Button the browser shows me this:
<?php
if(isset($_POST['login'])) {
echo "Hello " . $_GET["username"];
}
?>
I guess it's a syntax issue but I can't find it. Maybe you see it.
Thanks a lot!
My advice would be to use:
<?php
if (isset($_POST['login']))
{
$username = $_POST['username'];
if (!empty($username))
{
echo "hello $username";
} else {
echo "You must fill in the username!";
}
}
?>
To be honest, I would change index.html to index.php and place it into the top of that page so all errors etc are passed through one file.
you should change that $_GET["username"] to $_POST["username"] variable to work it correctly
<?php
if(isset($_POST['login'])) {
echo "Hello " . $_POST["username"];
}
?>
Do you have the php code in app.php? If you have then you have not enabled mod_php in Apache. I would recommend you to use wampserver (on windows) since that takes care of the basic apache/php configuration.
http://www.wampserver.com/en/
EDIT: You can not just execute your php code without having a webserver. Opening HTML files in your browser is client side and php is server side.
First I think you don't have apache server running to make your PHP code works correctly.
And you are sending the data using POST no GET, you must use the POST method to handle the data.
<?php
if(isset($_POST['login'])) {
echo "Hello " . $_POST["username"];
}
?>

Login issue with PHP Session

Hi I have meet a problem here.
I need to log in an account here
but after i key in all the details and click Sign-In the page will redirect me back to the log in page. But actually the account is already logged in just that it cant redirect back to the Home Page after log in.
What problem is this? Im using Session.
and i put my session_start in connect.php(which is use to connect to database)
Below is The Code
<?php error_reporting(0) ?>
<?php
include_once 'connect.php';
//Code Refer to http://www.w3schools.com/php/func_http_setcookie.asp
if(isset($_SESSION['user'])!="")
{
header("Location: Home.php");
}
if(isset($_POST['btn-login']))
{
$username = mysql_real_escape_string($_POST['username']);
$upass = mysql_real_escape_string($_POST['password']);
$res=mysql_query("SELECT * FROM user WHERE u_username='$username'");
$row=mysql_fetch_array($res);
if($row['u_password']==md5($upass))
{
$_SESSION['user'] = $row['u_ID'];
header("Location: Home.php");
}
else
{
?>
<script>alert('wrong details');</script>
<?php
}
?>
<?php
$year = time() + 31536000;
setcookie('rememberme', $_POST['username'], $year);
if ($_POST['rememberme'])
{
setcookie ('rememberme',$_POST['username'], $year);
}
else
{
setcookie(rememberme, $past);
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<link rel="stylesheet" href="Style.css" type="text/css" />
</head>
<body>
<div id="header">
<div id="left">
<label>AngelService</label><br/>
<p>Royal Borough of Greenwich</p>
</div>
</div>
<center> Home Page | View Post | Post A Service</center>
<center>
<div id="login-form">
<form method="post">
<table align="center" width="30%" border="0">
<tr>
<td><input type="text" name="username" placeholder="Your Username" required value="<?php
echo $_COOKIE['rememberme']; ?>"/>
</td>
</tr>
<tr>
<td><input type="password" name="password" placeholder="Your Password" required />
</td>
</tr>
<tr>
<td><button type="submit" name="btn-login">Sign In</button></td>
</tr>
<tr>
<td>
<input type="checkbox" name="rememberme" value="rememberme" style="font- size:6px;"> Remember Me<br>
</td>
</tr>
<tr>
<td>
Sign Up Here</td>
</tr>
</table>
</form>
</div>
</center>
<div id="footer">
<div id="center" align="center">
<br/>
<p>Angel Services | Royal Borough of Greenwich | Created By UOG Student: Kuai Boon Ting</p>
</div>
</div>
</body>
</html>
You are missing action="Your redirection page" in form tag i.e.,
<form method="post" action="forexample-Home.php">
.....
</form>
There are several things you can do to improve your code. For starters, you do not need to close and open PHP tags directly after each other, like you have
<?php error_reporting(0) ?>
<?php
include_once 'connect.php';
could just be
<?php error_reporting(0);
include_once 'connect.php';
The statement if(isset($_SESSION['user'])!="") doesn't do exactly what you think it does. isset($_SESSION['user']) returns a boolean (true/false), so checking whether or not a boolean is empty won't work. You can do if (!empty($_SESSION['user'])) {... to check if it's set and if it's empty or not. Check out the documentation for isset() and documentation for empty().
For your actual problem though: Note also that your header(); functions cannot be called after any output is made to the browser (any whitespace, HTML or PHP echo). This would appear as a PHP Warning, which will be reported should you put error_reporting(-1); instead of ignoring all errors (as you currently are doing with having error_reporting set to 0).
The other answer suggested using the HTML action-attribute for the form, but in case the login is invalid, it's best to have it sent to the same page, and only redirect should the login be valid. This is called "validate and redirect".
These pointers below are just to improve your code, and not necessarily the cause of your problem.
If you want to set a cookie, it has to be done before any and all output is sent to the browser (see this post), so in case the if($row['u_password']==md5($upass)) statement fails, and it enters the else-brackets, your cookie will not be set.
You should stop using mysql_* functions if you can. They are deprecated, and will be removed in the future. Switch over to mysqli_* or PDO instead. (Check out this post).
Usage of md5 hashing is not that secure. If you have PHP 5.5.0 or higher, you should perhaps look into usage of password_hash and password_verify
After every header("Location: ...."); you should always put a exit;, so that the code stops executing after it's redirecting. (Check out this post).

php header gives me the error [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 7 years ago.
First of all don't think that its dublicate question.
I have tried all sollutions but nothing helps me.
I get the following error:
"Cannot modify header information - headers already sent by (output started at /home/gogiavag/public_html/maxkapital/user.php:7) in /home/gogiavag/public_html/maxkapital/func.php on line 4"
All pages I have converted to utf8 (without BOM). I have no leading space in begining, but besides nothing helps.
Here is my code:
login.php
<?php session_start();?>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<?php include "header.php"; require_once 'func.php';?>
<form method="POST" action="user.php">
<table style="margin-top: 10px;">
<tr>
<td><label for ="txtuser">name:</label></td>
<td><input type="text" style="padding:5px;" id="txtuser" name="txtuser" value="<?php if (isset($_SESSION['txtuser'])
){echo $_SESSION['txtuser'];}else{echo '';} ?>" </input></td>
</tr>
<tr>
<td><label for ="txtpassword">password:</label></td>
<td><input type="password" style="padding:5px;" id="txtpassword" name="txtpassword"> </input></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value ="Enter" style="padding:5 55 5 55;background-color:#3f4194;color:#fff;" name="btnsubmit" id="btnsubmit"> </td>
</tr>
</table>
</form>
<?php
if (isset($_SESSION['err'])){
if ($_SESSION['err']===true){
echo gg_stringformat("<img src='error.png' style='margin-left:50px;'><img/> <span style='font-size:10pt; color:#ff0000'>{0}</span>", $_SESSION['errmsg']);
}
}
if(isset($_SESSION['err'])){unset ($_SESSION['err']);};
if(isset($_SESSION['errmsg'])){unset ($_SESSION['errmsg']);};
if(isset($_SESSION['txtuser'])){unset ($_SESSION['txtuser']);};
if(isset($_SESSION['txtpassword'])){unset ($_SESSION['txtpassword']);};
?>
</body>
</html>
user.php
<?php session_start();?>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<?php require_once'func.php';
if (!isset($_POST['btnsubmit'])){
gg_redirect('block.php');
exit;
}
$user=$_POST['txtuser'];
$pass=$_POST['txtpassword'];
$_SESSION['txtuser'] = $user;
$_SESSION['txtpassword'] = $pass;
if (gg_trim($user)===''){
$_SESSION['err']=true;
$_SESSION['errmsg']='User name required';
gg_redirect('login.php');
exit;
}elseif(gg_trim($pass)===''){$_SESSION['err']=true;$_SESSION['errmsg']='Password required';gg_redirect('login.php');
exit;
}
echo $user, "<BR>", $pass;
?>
</body>
</HTML>
header.php
<div id="divheader" >
<p> <img src="coins.png"></img>MAX_KAPITAL</p>
</div>
func.php begins with ...
<?php
mb_internal_encoding("UTF-8");
function gg_redirect($url){
header("location: $url");
}
....
It gives me the error when user don't enters password or username.
Please find error in my code.
thanks in advance.
regards George Gogiava
PHP is not lying to you, you indeed already started output at line 2 in user.php - you print <html> to response there.
Then you print <head> and some more HTML, then you call the function gg_redirect() from func.php if !isset($_POST['btnsubmit']), which causes the error, because it is not longer possible to send the redirect header since output was started already.
You need to check the inputs and possibly redirect before you send anything back to the client (apart of other response headers)., specifically, don't print any HTML before you're done handling the possible redirects:
<?php
// includes here - they must have no output!
// check if all is OK, set $redirectURL if redirect is needed to that URL
if ($redirectUrl) {
header("location: $redirectUrl");
exit(); // header() won't cause the script to stop executing
}
?>
<html>
<head>
...
The files included before the redirect must not print any output - not even a blank line, so they must all have <?php as the first characters of the file, whole file must be PHP without any output to response body, and must end with ?> with no newline or space afterwards (PHP may trim some whitespace in this case but don't rely on that).
Call to session_start() is safe and can be before the redirect (useful if you need session variables), since it will not send any response body. It may set a cookie, but that's OK because cookies are sent in headers.
While #Jiri already explained it correctly, to be more explicit:
move this:
<?php require_once'func.php';
if (!isset($_POST['btnsubmit'])){
gg_redirect('block.php');
exit;
}
to the very top of you php script, maybe even adding the first line to it like this:
<?php
if (!isset($_POST['btnsubmit'])){
gg_redirect('block.php');
exit;
}
require_once'func.php';
session_start();
?>
and then the rest of your page.
EDIT
The func.php is adding headers, by including it before your redirect, you get that error. Move the inlude line to some place after the redirect or check your func.php, see the edited code above

if-elseif-else statement not working

The following code is supposed to check accoroding to the superglobals and output one text field for username. Instead it gives out 3. I checked the code thoroughly, but cannot seem to find any error. I am relatively new to PHP, if someone could guide me.
<? session_start();
// for demo, else these would be in some database
define("USER", "abcde");
define("PASS", "zxcvb");
if (isset($_POST["user"]) && isset($_POST["pass"]))
{
if ($_POST["user"] == USER && $_POST["pass"] == PASS)
{
$_SESSION["authenticated"] = true;
setcookie("user", $_POST["user"], time() + 7 * 24 * 60 * 60);
$host = $_SERVER["HTTP_HOST"];
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
header("Location: http://$host$path/home.php");
exit;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Log In</title>
</head>
<body>
<form action="<?= $_SERVER["PHP_SELF"] ?>" method="post">
<table>
<tr>
<td>Username:</td>
<td>
<? if (isset($_POST["user"])): ?>
<input name="user" type="text" value="<?= htmlspecialchars($_POST["user"]) ?>">
<? elseif (isset($_COOKIE["user"])): ?>
<input name="user" type="text" value="<?= htmlspecialchars($_COOKIE["user"]) ?>">
<? else: ?>
<input name="user" type="text" value="">
<? endif ?>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input name="pass" type="password"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Log In"></td>
</tr>
</table>
</form>
</body>
</html>
You are using short tags (<?) rather than formal tags, which may not be enabled in your php.ini
If you have access to change the php.ini, change short_open_tag = Off or short_open_tag = 0 to short_open_tag = On or short_open_tag = 1 respectively.
Alternatively, add the line <?php ini_set('short_open_tag','1'); ?> at the beginning of the file, but this is less than ideal, and would be better by changing all <? to <?php
Not possible. if will not execute multiple paths, e.g:
php > if (1==1) { echo 'foo'; } else if (1==1) { echo 'bar'; }
foo
php >
even though both conditions evaluate to true, only the FIRST matched condition has its code executed, and then the if is done.
If you get all three fields, then most like your PHP is misconfigured and NONE of the php is being executed, and you're getting the raw php output. Since browsers ignore/hide unknown tags, the PHP code is simply not rendered and you see all of the non-php code. e.g. check your browser's "view source", and you'll see the php code there, which means you've got major problems on the server.
To execute PHP on localhosts, like XAMP and WAMP, you must use <?php at the beginning of the document, or it will output the script like a <p> element in HTML.
I think your server does not support short tags.
You should try to replace <? by <?php
See this documentation to know more about that.
You can of course allow short tags but it is really not recommended.

header() function in php : No any redirection!

I have written a very very very simple!! script in php. header redirection not working.
1- encoding : UTF-8 without BOM
2- with adding ob_start() the problem is countiueing.
What is wrong in my code;
login.php:
<?php session_start();
require_once("funcs.php");
db_connection();
$username = $_POST['username'];
$password = $_POST['pwd'];
$submit = $_POST['login'];
if($submit){
if (!filled_out($_POST)) {
echo "please fill all fields";
}
else{
$query = "SELECT * FROM *** WHERE username ='{$username}' AND password ='{$password}'";
$result = mysql_query($query);
if(mysql_num_rows($result) == 1){
$found_user = mysql_fetch_array($result);
$_SESSION['id'] = $found_user['id'];
$_SESSION['username'] = $found_user['username'];
$_SESSION['password'] = $found_user['password'];
setcookie(session_name(), '', time()+86400, '/');
header("Location: tst.php");
}
else{
echo "incorrect username or password";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
<label for="username">
Username:
</label>
<input type="text" name="username" id="username" />
</p>
<p>
<label for="textfield">
Password
</label>
<input type="password" name="pwd" id="pwd" />
</p>
<p>
<input name="login" type="submit" id="login" value="Log in" />
</p>
</form>
</body>
</html>
<?php
db_disconnect();
?>
and tst.php:
<?php session_start();
require_once("funcs.php");
if (!isset($_SESSION['id'])){
header("Location : login.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table id="structure">
<tr>
<td id="navigation"> </td>
<td id="page"><?php echo "welcome"."". $_SESSION['username']; ?></td>
</tr>
</table>
</body>
</html>
wthit oppening tst.php directly, header() doesnot redirect to login.php
Try adding die():
header("Location: tst.php");
die();
You should always add a die() because a location header is just a request to the browser to change the page. If you don't die(), the rest of the page will still reach the browser, including possibly sensitive data the user is not meant to see.
Try removing the space after "Location":
header("Location: login.php");
Please heed my comment about formatting your code correctly as it's extremely difficult to spot anything else that may be amiss.
Check for white space before your opening <?php tags. It's hard to tell from your formatting here whether there is any, but the whitespace will be sent before your code executes, preventing headers. Also check for white space after any closing tags in included files. (better practice is to omit closing tags altogether)
old answer
You're using setcookie() which will send headers, then trying to redirect. You cannot redirect once headers have been sent. (sorry, this was incorrect)
I guess the redirect works, but you overwrite the Session-Cookie with an empty value. So the tst.php creates a new empty Session and redirects back to login.php.
Try:
// DELETE this line: setcookie(session_name(), '', time()+86400, '/');
header("Location: tst.php?".SID);
Importent: header+session always need SID for not loosing the session!
Corrected: Thanks to #Pekka.
header is not just a php function. It really modifies a part of http header, so it is impossible to have a part of header, then html data, then another header. To make it work, you should put your header at the beginning of the file, before any html output is done.
The redirection can take a relative or absolute URL. The problem is with the space BEFORE the colon. Try it like this:
header("Location: whatever.php");
As well as the other answers, the Location: header should contain an absolute URL, example header("Location: http://example.com/");
you need to put an exit() or die() after the header function - otherwise the rest of the script will continue to execute.

Categories