/    Sign up×
Community /Pin to ProfileBookmark

If i want to use header(“Location: [url]www.url.com[/url]“) after output, how should i place it?

what i have now is something like this…

[code=php]
<html>
<body>
<?
if($_GET[‘str’] == 1) {
header(“Location: [url]http://www.yahoo.com[/url]”);
}
?>
</body>
</html>
[/code]

i want the script to be directed to another site when the get string, “str”, is equals to 1. but if i were to do this, i think this wont work and i will get an error like…
Warning: Cannot modify header information – headers already sent by (output started at /home/usr/public_html/admin/login.php:25) in /home/usr/public_html/admin/login.php on line 53

i example i gave above is not what i had in the script but the meaning is exactly the same. I have an output before the start of my script and after a session_start function. when i login the script and the session variable returns true, i want it to direct the page to another page. but i get an error of cannot modify header information.

redirection may not be the only case. in some cases when i want to change the charset of the document if any condition is met, i have to use headers as well and chances are i will get this error too.
how should i solve this problem?
thanks

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 03.2005 — [code=php]
<?php
if($_GET['str'] == 1) {
header("Location: http://www.yahoo.com/");
exit;
}
?>
<html>
<body>
</body>
</html>
[/code]
×

Success!

Help @v_E_r5e 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...