You are here: Re: $_SERVER[] « All PHP « IT news, forums, messages
Re: $_SERVER[]

Posted by Juliette on 08/20/06 13:30

Flaming Corncob wrote:
> In article <34fef$44e80669$8259c69c$18973@news2.tudelft.nl>,
> "Rik" <luiheidsgoeroe@hotmail.com> wrote:
>
>> Flaming Corncob wrote:
>>> In article <44e794d7$0$47828$dbd41001@news.wanadoo.nl>,
>>> Juliette <jrf_no_spam@jokeaday.net> wrote:
>>>
>>>> Flaming Corncob wrote:
>>>>> In article <44e75e66$0$66091$dbd4d001@news.wanadoo.nl>,
>>>>> Juliette <jrf_no_spam@jokeaday.net> wrote:
>>>>>
>>>>>> Flaming Corncob wrote:
>>>>>>> Using $_SERVER['HTTP_REFERER'], you might get (for example)
>>>>>>> http://widgets.com/test/test_new.php?page=2. Is there a way to
>>>>>>> extract the "widgets.com/test/test_new.php" portion of it and
>>>>>>> store it in a string?
>>>>>>>
>>>>>>> Thanks much.
>>>>>> Have a look at: http://www.php.net/parse-url
>>>>> Yep, saw that after the fact. Unfortunately ended up with another
>>>>> problem. Sometimes the url comes through as blank. Nadda. Nothing.
>>>> That is not a 'problem', but a feature.
>>>> Think real world: someone might have bookmarked the page. No
>> referrer
>>>> will be send then.
>>>> Also, the referrer can quite easily be spoofed or removed by a
>>>> semi-experienced web-user.
>>>> Never make your code dependant on it.
>>>>
>>>> Have a look at the documentation of the $_SERVER array and the user
>>>> comments.
>>> So there's no real way to force a page to check for a certain
>>> condition
>>> and reroute itself to itself to set a page for example? ... I pulled
>>> it
>>> off by having one single variable used to equal one thing and if
>> it's
>>> not it assumes the user is visiting the site from somewhere other
>> than
>>> in the site itself.. if that happens it sets the key variable to
>> what
>>> it expects and reroutes back to itself passing the key in the url. I
>>> just hoped there was a better way of doing it.
>> Is soons a very lot like a session? What exactly are you planning to
>> use it for?
>>
>> Grtz,
>
> I use it in general. I usually code an index page that handles
> everything, and it needs a way of defaulting to the home page... and
> last night I discovered another nice toy. isset().


Providing you are on a *nix server, if your index page will handle the
get variables to decide which page to present, you can just reroute
using .htaccess with something like this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^index\.php.*$ [OR]
RewriteCond %{REQUEST_URI} !^images/.*\.(jpg|gif|png)$ [OR]
RewriteCond %{REQUEST_URI} !^cgi-bin/.*$

RewriteRule ^([a-zA-Z0-9_]*)/?$ index\.php?id=$1 [L]

The three conditions are for:
a) avoiding the page redirecting if index is asked for
b) avoiding image requests from your page being redirected
c) avoiding the cgi-bin scripts being redirected

The rewrite rule is one I use myself, you will have to think up what
would be a good one for your url scheme, but this one will just take any
alphanum character (plus the underscore) after the base address
(www.yoursite.com/) and send it as a get variable called id to the
index.php script.


If you don't uneed get variables, you can just use something like:

RedirectMatch permanent ^/.*$ http://www.yoursite.com/index.php


For more information, have a look at some .htaccess tutorials or the
Apache documentation on it.

 

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

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