Ask a Question related to PHP Development, Design and Development.
-
Jack Turner #1
request REMOTE_ADDR and use if/else statment, HELP PLEASE!
Hi,
I'm particularly new to PHP and i would like some help translating the
following from ASP to PHP.
It basically request "REMOTE_ADDR" (ip address of browser) and if its the
same as the one specified, then it display's the page, if its anything other
then the specified ip, it just display's an access deniged page
(error.asp?event=wrongip) and stops processing the page further.
Thanks in advance and heres the code:
<% if request.servervariables("REMOTE_ADDR") <> "82.x.x.x" then
response.redirect "error.asp?event=wrongip"
end if %>
(page script / html goes here of the content that is restricted to ip)
--
Regards, Posting from:
Jack Turner? ¤Sunny Ol' Wolverhampton
Jack Turner Guest
-
CGI Variables CGI.REMOTE_ADDR
I am using cold fusion MX and Iplannet. Is it possible to find the client IP Address using the CGI variable, CGI.REMOTE_ADDR in CFC. it is showng... -
$ENV{'REMOTE_ADDR'}
Dan Muey wrote: I'm no security expert, but how can these be spoofed? They don't come from the request headers, but are derived from the TCP... -
#24515 [Fbk->NoF]: $_SERVER[remote_addr] different to $remote_addr
ID: 24515 Updated by: sniper@php.net Reported By: phpbug at easihosting dot co dot uk -Status: Feedback... -
#24515 [Opn->Fbk]: $_SERVER[remote_addr] different to $remote_addr
ID: 24515 Updated by: sniper@php.net Reported By: phpbug at easihosting dot co dot uk -Status: Open +Status: ... -
#24515 [Fbk->Opn]: $_SERVER[remote_addr] different to $remote_addr
ID: 24515 User updated by: phpbug at easihosting dot co dot uk Reported By: phpbug at easihosting dot co dot uk -Status: ... -
Richard Grove - ®ed Eye Media #2
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
other>
> I'm particularly new to PHP and i would like some help translating the
> following from ASP to PHP.
>
> It basically request "REMOTE_ADDR" (ip address of browser) and if its the
> same as the one specified, then it display's the page, if its anything> then the specified ip, it just display's an access deniged page
> (error.asp?event=wrongip) and stops processing the page further.
>
> Thanks in advance and heres the code:
>
>
> <% if request.servervariables("REMOTE_ADDR") <> "82.x.x.x" then
> response.redirect "error.asp?event=wrongip"
> end if %>
> (page script / html goes here of the content that is restricted to ip)
>
>
> --
> Regards, Posting from:
> Jack Turner? ¤Sunny Ol' Wolverhampton
>
>
Richard Grove - ®ed Eye Media Guest
-
Richard Grove - ®ed Eye Media #3
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
the> > I'm particularly new to PHP and i would like some help translating the
> > following from ASP to PHP.
> >
> > It basically request "REMOTE_ADDR" (ip address of browser) and if its> other> > same as the one specified, then it display's the page, if its anything>> > then the specified ip, it just display's an access deniged page
> > (error.asp?event=wrongip) and stops processing the page further.
> >
> > Thanks in advance and heres the code:
> >
> >
> > <% if request.servervariables("REMOTE_ADDR") <> "82.x.x.x" then
> > response.redirect "error.asp?event=wrongip"
> > end if %>
> > (page script / html goes here of the content that is restricted to ip)
> >
> >
> > --
> > Regards, Posting from:
> > Jack Turner? ¤Sunny Ol' Wolverhampton
> >
> >
>
<?php
if(ereg("^82.",$HTTP_SERVER_VARS['REMOTE_ADDR'])) {
header("somepage");
}
else {
header("someotherpage");
}
untested though as I am not an expert in regular expressions.
Regards
Richard Grove
[url]http://www.shopmaker.co.uk[/url] - UK Ecommerce Shop Systems
Richard Grove - ®ed Eye Media Guest
-
Jack Turner #4
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
In a weird place they call a newsgroup, Richard Grove - ®ed Eye Media
woke up and posted news:41529c38$0$41784$65c69314@mercury.nildram.net
using info®redeyemedia.co.uk as their email address:
|||| I'm particularly new to PHP and i would like some help translating
|||| the following from ASP to PHP.
||||
|||| It basically request "REMOTE_ADDR" (ip address of browser) and if
|||| its the same as the one specified, then it display's the page, if
|||| its anything other then the specified ip, it just display's an
|||| access deniged page (error.asp?event=wrongip) and stops processing
|||| the page further.
||||
|||| Thanks in advance and heres the code:
||||
||||
|||| <% if request.servervariables("REMOTE_ADDR") <> "82.x.x.x" then
|||| response.redirect "error.asp?event=wrongip"
|||| end if %>
|||| (page script / html goes here of the content that is restricted to
|||| ip)
||||
||||
|||| --
|||| Regards, Posting from:
|||| Jack Turner? ¤Sunny Ol' Wolverhampton
||||
||||
|||
|||
||
||
||
|| <?php
|| if(ereg("^82.",$HTTP_SERVER_VARS['REMOTE_ADDR'])) {
|| header("somepage");
|| }
|| else {
|| header("someotherpage");
|| }
||
|| untested though as I am not an expert in regular expressions.
||
|| Regards
|| Richard Grove
|| [url]http://www.shopmaker.co.uk[/url] - UK Ecommerce Shop Systems
that just brings a blank page up :-(, any idea's?
--
Regards, Posting from:
Jack Turner? ¤Sunny Ol' Wolverhampton
Jack Turner Guest
-
carlos #5
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
Jack Turner wrote:
[snip]> In a weird place they call a newsgroup, Richard Grove - ®ed Eye Media
> woke up and posted news:41529c38$0$41784$65c69314@mercury.nildram.net
> using info®redeyemedia.co.uk as their email address:
> |||| I'm particularly new to PHP and i would like some help translating
> |||| the following from ASP to PHP.
[snip]> |||| <% if request.servervariables("REMOTE_ADDR") <> "82.x.x.x" then
> |||| response.redirect "error.asp?event=wrongip"
> |||| end if %>
> |||| (page script / html goes here of the content that is restricted to
> |||| ip)
[snip]> ||
> || <?php
> || if(ereg("^82.",$HTTP_SERVER_VARS['REMOTE_ADDR'])) {
> || header("somepage");
> || }
> || else {
> || header("someotherpage");
> || }
First a correct translation of the asp should be:> that just brings a blank page up :-(, any idea's?
<?php
if ($_SERVER['REMOTE_ADDR'] != "82.x.x.x"){
header("location: error.php?event=wrongip");
}
?>
<html>
(page script / html goes here of the content that is restricted to ip)
Second it *must* be the first line in your page, anything else than the
script will trigger header sending :)
Richard: the . in the "^82." regexp will be interpreted as 'any
character'. if you'd like to match against the dot you should "^82\."
escape the bugger.
HTH
Carlos
carlos Guest
-
Jack Turner #6
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
In a weird place they call a newsgroup, carlos" <"no <spam woke up and
posted news:4154523d$0$21260$6c56d894@diablo.nl.easynet.n et using "no
<spam"@bitrot.nl as their email address:
|| Jack Turner wrote:
||| In a weird place they call a newsgroup, Richard Grove - ®ed Eye
||| Media woke up and posted
||| news:41529c38$0$41784$65c69314@mercury.nildram.net using
||| info®redeyemedia.co.uk as their email address:
||||||| I'm particularly new to PHP and i would like some help
||||||| translating the following from ASP to PHP.
||
|| [snip]
||
||||||| <% if request.servervariables("REMOTE_ADDR") <> "82.x.x.x" then
||||||| response.redirect "error.asp?event=wrongip"
||||||| end if %>
||||||| (page script / html goes here of the content that is restricted
||||||| to ip)
||
|| [snip]
||
|||||
||||| <?php
||||| if(ereg("^82.",$HTTP_SERVER_VARS['REMOTE_ADDR'])) {
||||| header("somepage");
||||| }
||||| else {
||||| header("someotherpage");
||||| }
||
|| [snip]
||
||| that just brings a blank page up :-(, any idea's?
||
|| First a correct translation of the asp should be:
||
|| <?php
|| if ($_SERVER['REMOTE_ADDR'] != "82.x.x.x"){
|| header("location: error.php?event=wrongip");
|| }
|||
|| <html>
|| (page script / html goes here of the content that is restricted to
|| ip)
||
||
|| Second it *must* be the first line in your page, anything else than
|| the script will trigger header sending :)
||
||
|| Richard: the . in the "^82." regexp will be interpreted as 'any
|| character'. if you'd like to match against the dot you should "^82\."
|| escape the bugger.
||
||
|| HTH
|| Carlos
can this be put in an include_security.php and include this in all the pages
so i can change the include_security.php to change all the pages, ie dynamic
ip.
Thanks in advance
--
Regards, Posting from:
Jack Turner? ¤Sunny Ol' Wolverhampton
Jack Turner Guest
-
Jack Turner #7
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
In a weird place they call a newsgroup, Jack Turner woke up and posted
news:BxY4d.667$ED.147@text.news.blueyonder.co.uk using
[email]Jack@jt3k(nospammy).co.uk[/email] as their email address:
|| In a weird place they call a newsgroup, carlos" <"no <spam woke up
|| and posted news:4154523d$0$21260$6c56d894@diablo.nl.easynet.n et
|| using "no <spam"@bitrot.nl as their email address:
|||| Jack Turner wrote:
||||| In a weird place they call a newsgroup, Richard Grove - ®ed Eye
||||| Media woke up and posted
||||| news:41529c38$0$41784$65c69314@mercury.nildram.net using
||||| info®redeyemedia.co.uk as their email address:
||||||||| I'm particularly new to PHP and i would like some help
||||||||| translating the following from ASP to PHP.
||||
|||| [snip]
||||
||||||||| <% if request.servervariables("REMOTE_ADDR") <> "82.x.x.x"
||||||||| then response.redirect "error.asp?event=wrongip"
||||||||| end if %>
||||||||| (page script / html goes here of the content that is
||||||||| restricted to ip)
||||
|||| [snip]
||||
|||||||
||||||| <?php
||||||| if(ereg("^82.",$HTTP_SERVER_VARS['REMOTE_ADDR'])) {
||||||| header("somepage");
||||||| }
||||||| else {
||||||| header("someotherpage");
||||||| }
||||
|||| [snip]
||||
||||| that just brings a blank page up :-(, any idea's?
||||
|||| First a correct translation of the asp should be:
||||
|||| <?php
|||| if ($_SERVER['REMOTE_ADDR'] != "82.x.x.x"){
|||| header("location: error.php?event=wrongip");
|||| }
|||||
|||| <html>
|||| (page script / html goes here of the content that is restricted to
|||| ip)
||||
||||
|||| Second it *must* be the first line in your page, anything else than
|||| the script will trigger header sending :)
||||
||||
|||| Richard: the . in the "^82." regexp will be interpreted as 'any
|||| character'. if you'd like to match against the dot you should
|||| "^82\." escape the bugger.
||||
||||
|||| HTH
|||| Carlos
||
|| can this be put in an include_security.php and include this in all
|| the pages so i can change the include_security.php to change all the
|| pages, ie dynamic ip.
||
|| Thanks in advance
||
||
|| --
|| Regards, Posting from:
|| Jack Turner? ¤Sunny Ol' Wolverhampton
<?php include 'include_security.php'; ?>
<html>
<head>
i managed it and put the following in the include_sevurity file:
<?php
if ($_SERVER['REMOTE_ADDR'] != "82.337.195.66"){
header("location: error.asp?event=wrongip");
}
php?>
--
Regards, Posting from:
Jack Turner? ¤Sunny Ol' Wolverhampton
Jack Turner Guest
-
Andy Hassall #8
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
On Fri, 24 Sep 2004 18:21:34 +0200, carlos <"no <spam"@bitrot.nl> wrote:
<nitpick>> header("location: error.php?event=wrongip");
The Location header must be an absolute URI, not a relative one.
HTTP/1.1, sec 14.30:
[url]http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30[/url]
</nitpick>
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Andy Hassall Guest
-
Jack Turner #9
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
In a weird place they call a newsgroup, Andy Hassall woke up and posted
news:th59l0t2nl4kjvotrcek8c487bntpvvg0e@4ax.com using [email]andy@andyh.co.uk[/email]
as their email address:
|| On Fri, 24 Sep 2004 18:21:34 +0200, carlos <"no <spam"@bitrot.nl>
|| wrote:
||
||| header("location: error.php?event=wrongip");
||
|| <nitpick>
||
|| The Location header must be an absolute URI, not a relative one.
||
|| HTTP/1.1, sec 14.30:
|| [url]http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30[/url]
||
||
|| </nitpick>
||
|| --
|| Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
|| <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis
|| tool
the relative one seems to of worked, as all the files i want to protect are
in the same directory
--
Regards, Posting from:
Jack Turner? ¤Sunny Ol' Wolverhampton
Jack Turner Guest
-
Andy Hassall #10
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
On Fri, 24 Sep 2004 23:01:50 GMT, "Jack Turner" <Jack@jt3k(nospammy).co.uk>
wrote:
It may have worked for your particular configuration, server, and browser, as>In a weird place they call a newsgroup, Andy Hassall woke up and posted
>news:th59l0t2nl4kjvotrcek8c487bntpvvg0e@4ax.com using [email]andy@andyh.co.uk[/email]
>as their email address:
>|| On Fri, 24 Sep 2004 18:21:34 +0200, carlos <"no <spam"@bitrot.nl>
>|| wrote:
>||
>||| header("location: error.php?event=wrongip");
>||
>|| <nitpick>
>||
>|| The Location header must be an absolute URI, not a relative one.
>||
>|| HTTP/1.1, sec 14.30:
>|| [url]http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30[/url]
>||
>||
>|| </nitpick>
>
>the relative one seems to of worked, as all the files i want to protect are
>in the same directory
one or more have compensated for the invalid output, but it's still breaking
the HTTP standard.
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Andy Hassall Guest
-
Jack Turner #11
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
In a weird place they call a newsgroup, Andy Hassall woke up and posted
news:daa9l0h9a1dofs64rnslkartvqk2titb9i@4ax.com using [email]andy@andyh.co.uk[/email]
as their email address:
|| On Fri, 24 Sep 2004 23:01:50 GMT, "Jack Turner"
|| <Jack@jt3k(nospammy).co.uk> wrote:
||
||| In a weird place they call a newsgroup, Andy Hassall woke up and
||| posted news:th59l0t2nl4kjvotrcek8c487bntpvvg0e@4ax.com using
||| [email]andy@andyh.co.uk[/email]
||| as their email address:
||||| On Fri, 24 Sep 2004 18:21:34 +0200, carlos <"no <spam"@bitrot.nl>
||||| wrote:
|||||
|||||| header("location: error.php?event=wrongip");
|||||
||||| <nitpick>
|||||
||||| The Location header must be an absolute URI, not a relative one.
|||||
||||| HTTP/1.1, sec 14.30:
||||| [url]http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30[/url]
|||||
|||||
||||| </nitpick>
|||
||| the relative one seems to of worked, as all the files i want to
||| protect are in the same directory
||
|| It may have worked for your particular configuration, server, and
|| browser, as one or more have compensated for the invalid output, but
|| it's still breaking the HTTP standard.
||
|| --
|| Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
|| <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis
|| tool
How?
Theres relative and absolout links, which will work fine.
--
Regards, Posting from:
Jack Turner? ¤Sunny Ol' Wolverhampton
Jack Turner Guest
-
Andy Hassall #12
Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!
On Fri, 24 Sep 2004 23:47:36 GMT, "Jack Turner" <Jack@jt3k(nospammy).co.uk>
wrote:
The quote from the standard:>|||||| header("location: error.php?event=wrongip");
>|||||
>||||| <nitpick>
>|||||
>||||| The Location header must be an absolute URI, not a relative one.
>|||||
>||||| HTTP/1.1, sec 14.30:
>||||| [url]http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30[/url]
>|||||
>|||||
>||||| </nitpick>
>|||
>||| the relative one seems to of worked, as all the files i want to
>||| protect are in the same directory
>||
>|| It may have worked for your particular configuration, server, and
>|| browser, as one or more have compensated for the invalid output, but
>|| it's still breaking the HTTP standard.
>
>How?
>
>Theres relative and absolout links, which will work fine.
"
14.30 Location
The Location response-header field is used to redirect the recipient to a
location other than the Request-URI for completion of the request or
identification of a new resource. For 201 (Created) responses, the Location is
that of the new resource which was created by the request. For 3xx responses,
the location SHOULD indicate the server's preferred URI for automatic
redirection to the resource. The field value consists of a single absolute URI.
Location = "Location" ":" absoluteURI
An example is:
Location: [url]http://www.w3.org/pub/WWW/People.html[/url]
"
A relative URI is not an absouteURI and so does not match the definition in
the standard.
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Andy Hassall Guest



Reply With Quote

