Reply to Re: forbidden error

Your name:

Reply:


Posted by Michael Fesser on 05/29/07 11:34

..oO(Kevin Raleigh)

>using the following code produces the following error
>
>> <?php
>> header("location: $_POST['location']");
>> exit;
>> ?>

Syntax error inside the string. It should be

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

or

header("Location: {$_POST['location']}");

>My "Guess" is that it will only take a string, variable, or number as an
>argument.
>So I tried this:
>
><?php
>
> $id = $_POST[ 'id'];
>
> if($id=="MSN") {
> $location = "http://www.msn.com/";
> } else if ($id == "php"){
>[...]

These IDs don't match the IDs in your form. The script won't perform any
redirect at all.

> header("location: 'location'");

Logical error, should be "Location: $location".

> exit;
>
> ?>
>
>This gives me a 404 file not found error

Correct, because the browser receives the string 'location' as the
redirect URL, which obviously don't exist (and BTW violates the HTTP
RFC).

>So I tried this:
><?php
>
> $id = $_POST[ 'id'];
> echo ("$id");
>?>
>
>From this:
>
><form method="post" action="do_redirect.php">
> <select name="id" size=1>
> <option value="http://www.msn.com/">MSN</option>
> <option value="http://www.php.net/">Php.net</option>
> <option value="http://www.slashdot.org/">Slashdot</option>
> <option value="http://www.linuxchix.org/">Linuxchix</option>
> </select> <input type="submit" value="Go">
></form>
>And have this error:
>
>http://www.php.net/ Error in my_thread_global_end(): 1 threads didn't exit
>
>I am guessing that my thread doesn't exist, but why?

According to Google it's a bug related to the MySQL client library and
has nothing to do with your current problem.

>Must be missing something extremely trivial

Let's start again, it's really simple. I would use a 2-dimensional array
to store the URLs and the site names:

$sites = array(
array('name' => 'MSN', 'url' => 'http://www.msn.com/'),
array('name' => 'PHP.net', 'url' => 'http://www.php.net/'),
array('name' => 'Slashdot', 'url' => 'http://www.slashdot.org/'),
array('name' => 'Linuxchix', 'url' => 'http://www.linuxchix.org/')
);

PHP will automatically assign a numeric key to every array element,
which you can use in your form. Creating that is easy:

[...]
print "<select name='id' size='1'>\n";
foreach ($sites as $id => $site) {
printf("<option value='%u'>%s</option>\n", $id, $site['name']);
}
print "</select>\n";
[...]

The form processing script would just have to check that the selected ID
is valid (it has to exist in the $sites array) and then do the redirect:

if (isset($_POST['id']) && isset($sites[$_POST['id']])) {
header("Location: {$sites[$_POST['id']]['url']}");
exit;
}

HTH
Micha

[Back to original 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

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