/    Sign up×
Community /Pin to ProfileBookmark

help with script

trying to create a script that will redirect user to a new webpage based on the user’s browser preference.

dont know if this script is right is the write way to write one

<? php

header (‘location: http://www.yahoo.com/http://www.msn.com/http://www.ask.com/‘ ) ;

? >

or

<?

header ( “location: $_post [location]”); exit;

?>

thanks

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@balloonbuffoonApr 02.2006 — [code=php]
<?

header("Location: ".$_POST["location"]);

?>
[/code]

This will redirect to whatever value is posted with the name "location". I'm not sure if that's all you're looking for, if not, pleace clarify.

--Steve
Copy linkTweet thisAlerts:
@benzspidaauthorApr 02.2006 — how about redirecting users to more than one location
Copy linkTweet thisAlerts:
@NogDogApr 02.2006 — You can only redirect to one location. You can have the location be a variable (as in b.b.'s post), but it will be incumbent upon you to write the logic that sets that variable's value. Not knowing what you mean by "based on the user's browser preference", I can't really suggest any specifics.
Copy linkTweet thisAlerts:
@benzspidaauthorApr 02.2006 — this is what my html code looks like

<html>

<head>

<title>

</title>

</head>

<body>

<form method= "post" Action="do_redirect.php">

<p>send me to:

<select name="location">

<option value= "http://www.msn.com/">msn</option>

<option value= "http://www.expedia.com/">expedia</option>

<option value= "http://www.microsoft.com/">microsoft</option>

</select>

<p><input type="submit" name="submit" value="Go!"></p>

</form>

</body>

</html>


so i am tryin to creat a script that will direct users to each of the option values not sure if u can do that, but thts what i am tryin to do
Copy linkTweet thisAlerts:
@NogDogApr 02.2006 — do_redirect.php:
[code=php]
<?php
// set location if provided from form, else set it to default page:
$location = (!empty($_POST['location'])) ? $_POST['location'] :
"http://your.site.com/index.php";
// go to that page:
header("Location: $location");
?>
[/code]
Copy linkTweet thisAlerts:
@benzspidaauthorApr 02.2006 — thnks

this is what i get when i out put the script


Warning: Cannot modify header information - headers already sent by (output started at C:rootdo_redirect.php:2) in C:rootdo_redirect.php on line 7


dont know what that mean just started learn php like 2 days a go
Copy linkTweet thisAlerts:
@benzspidaauthorApr 02.2006 — Thanks for the script its working fine
×

Success!

Help @benzspida 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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