request REMOTE_ADDR and use if/else statment, HELP PLEASE!

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. $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...
    3. #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...
    4. #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: ...
    5. #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: ...
  3. #2

    Default Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!

    >
    > 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
    >
    >


    Richard Grove - ®ed Eye Media Guest

  4. #3

    Default Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!


    > > 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



    Richard Grove - ®ed Eye Media Guest

  5. #4

    Default 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

  6. #5

    Default Re: request REMOTE_ADDR and use if/else statment, HELP PLEASE!

    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
    carlos Guest

  7. #6

    Default 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

  8. #7

    Default 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

  9. #8

    Default 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:
    > 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
    Andy Hassall Guest

  10. #9

    Default 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

  11. #10

    Default 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:
    >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
    Andy Hassall Guest

  12. #11

    Default 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

  13. #12

    Default 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:
    >|||||| 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.
    The quote from the standard:

    "
    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139