You are here: Re: Form field entry directs to diff URLs based on entry? « HTML « IT news, forums, messages
Re: Form field entry directs to diff URLs based on entry?

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация