Good afternoon,
I am new to the PHP lang all together.
I am wondering if anyone can help me out?
What I am trying to do is, on my index page have users answer the question of what their location is.
Then, pass this information off to location.php where it will direct the user to one of two web pages.
Any Ideas? and Thank you in advance,
Brian
index.html
<html>
<head></head>
<body>
<h2>Please Select Your Location</h2>
<p>
<form method="get" action="location.php">
<select name="location">
<option value="1">Ontario - Canada
<option value="2">Other Provinces - Canada
</select>
<input type="submit" value="Send">
</form>
</body>
</html>
location.php code
<?php
// get form selection
$location = $_GET['location'];
// check value and select appropriate item
if ($location == 1) {
$special = 'Location: http://www.url_A.com';
}
elseif ($location == 2) {
$special = 'Location: http://www.url_B.com';
}
?>
<?php header( $special); ?>
goto URL
Moderator: General Moderators
Re: goto URL
Well the code you posted looks like it will work in theory. Are you getting an error or unexpected result?
Re: goto URL
this is the error that comes up:
Warning: Cannot modify header information - headers already sent by (output started at /home/bria4964/public_html/location.php:3) in /home/bria4964/public_html/location.php on line 17
I cannot get it to forward.
Brian
Warning: Cannot modify header information - headers already sent by (output started at /home/bria4964/public_html/location.php:3) in /home/bria4964/public_html/location.php on line 17
I cannot get it to forward.
Brian
Re: goto URL
I just remembered hearing that spaces or empty line feeds above the <?php line should not be there..
I have removed them and it's working, Thank you for your reply.
I have removed them and it's working, Thank you for your reply.
Re: goto URL
You can clear out any printed data before the header data is executed like you say you did and that works. Some times this is impractical though, and you can put this on the first line of the page:
This will allow headers to be modified after the page is rendered.
Code: Select all
<?php
ob_start();
?>