Posted by Toby Inkster on 04/29/06 23:36
AtomicBob wrote:
> Example 1:
> user enters "Tony Tiger" in the field and hits submit.
> user is then sent to tonytiger.exampledomain.com.
>
> Example 2:
> user enters "johnnywalker" in the field and hits submit.
> user is then sent to johnnywalker.exampledomain.com.
Unless you use some client-side scripting, a form will always submit to
just one place.
However, that one place could be a script that looks at the form
submission and sends an HTTP 301 redirect to various different places
based on the form contents.
Here's some example code:
<form action="redirect.php" method="get">
<fieldset>
<legend>enter a name</legend>
<input name="name">
<input type="submit">
</fieldset>
</form>
<?php
// This file is "redirect.php".
// What is my domain name?
$mydomain = 'example.com';
// You used 'exampledomain.com' -- you might not have known
// that there exists a domain 'example.com' which is specially
// reserved just for examples.
// What name has the user entered?
$name = $_GET['name'];
// Convert down to lower case
$name = StrToLower($name);
// Remove all characters except 0-9 and a-z
$name = pReg_Replace('/[^0-9a-z]/', '', $name);
// Generate Final URL
$url = "http://{%s}.{$mydomain}/";
// Redirect
Header("HTTP/1.1 301 Redirect");
Header("Location: {$url}");
?>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
[Back to original message]
|