/    Sign up×
Community /Pin to ProfileBookmark

php: header function

i receive the following error while using the php header() function and get the following error: how can i remove this error

Warning: Cannot modify header information – headers already sent by (output started at E:Serverhtdocsapaceconn.php:2) in E:Serverhtdocsapaceap_adminap_index.php on line 22

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@redhatlookMay 28.2007 — You cannot output anything before header() function, that means no echo, no whitespaces no lines, nothing.

For example this code is bad:


echo 'abc';

header('xyz...');
[/QUOTE]
Copy linkTweet thisAlerts:
@mahfoozauthorMay 29.2007 — ok i followed but what is the solution for redirecting a user to login page so that when he/she press [B]browser history back button[/B] then he/she should be on the last visited page rather than to login page as in case of javascirpt redirection
Copy linkTweet thisAlerts:
@redhatlookMay 29.2007 — the best solution is the redirection using PHP of course.. this way


<?php

session_start();

if ($_SESSION['login']=='')

{

header('Location: login.php');

exit;

}

?>
[/QUOTE]
Copy linkTweet thisAlerts:
@mahfoozauthorMay 29.2007 — ok but what's the solution when i use some query to database like

[code=php]select date_of_birth from table where user_id='session_vriable'[/code]

and if data of birth lessthan some value than redirect to 1st page else redirect to 2nd page using header function
Copy linkTweet thisAlerts:
@redhatlookMay 29.2007 — you are developing some erotic site? if age<18 .. ? just kidding.. ?

use something like this..

[CODE]
<?php
// $age is read from db here ..
if ($age<30)
header('Location: under30.php'); else
header('Location: overequal30.php');
exit;
?>
[/CODE]
Copy linkTweet thisAlerts:
@mahfoozauthorMay 30.2007 — thanks but it is just an example query :eek:
×

Success!

Help @mahfooz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...