Reply to Re: Page redirect problem

Your name:

Reply:


Posted by Bryan King on 01/12/06 04:33

Pete,

It looks as if the code is re-directing correcting
http://mydomain.com/test.php?id=1, but the code executes again when that
page loads.

the code:

substr($_SERVER['REQUEST_URI'], 0, $pos);

returns nothing the second time it called, thus re-directing again to
http://mydomain.com.


Try this as a fix:

<?php
if (strpos($_SERVER['REQUEST_URI'], "&"))
{
$new_url = "http://mydomain.com" . substr($_SERVER['REQUEST_URI'], 0,
strpos($_SERVER['REQUEST_URI'], "&"));
header("Location: $new_url");
}
echo substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'],
"&"));
?>


Pete wrote:
> So I've made a script that just look for "&" in the url and removes all
> characters after that. So http://mydomain.com/test.php?id=1&sid=2 is
> redirected to http://mydomain.com/test.php?id=1
>
> <?php
> $pos = strpos($_SERVER['REQUEST_URI'], "&");
> $new_url = "http://mydomain.com".substr($_SERVER['REQUEST_URI'], 0, $pos);
> // print $new_url;
> header("Location: $new_url");
> ?>
>
> But it doesn't work. "print $new_url" outputs the correct url, but all
> requests are redirected to http://www.mydomain.com
>
> What is wrong?
>
>

[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

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