Serving a website based on source internet address ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Skybuck

    #1

    Serving a website based on source internet address ?

    Hello,

    Based on the source internet address a different version of the website
    should be presented/served to the user/browser.

    I would like to keep the script as simple as possible and it should
    replace the index.php.

    The script could look something like this in pseudo code:

    if SourceAddress = '143.3.5.1' then
    begin
    ShowBlueWebsite ; // load/show BlueIndex.htm
    end else
    if SourceAddress = '124.5.15.7' then
    begin
    ShowRedWebsite; // load/show RedIndex.htm
    end;

    Is this possible with php ?

    Bye,
    Skybuck.

  • Jerry Stuckle

    #2
    Re: Serving a website based on source internet address ?

    Skybuck wrote:
    Hello,
    >
    Based on the source internet address a different version of the website
    should be presented/served to the user/browser.
    >
    I would like to keep the script as simple as possible and it should
    replace the index.php.
    >
    The script could look something like this in pseudo code:
    >
    if SourceAddress = '143.3.5.1' then
    begin
    ShowBlueWebsite ; // load/show BlueIndex.htm
    end else
    if SourceAddress = '124.5.15.7' then
    begin
    ShowRedWebsite; // load/show RedIndex.htm
    end;
    >
    Is this possible with php ?
    >
    Bye,
    Skybuck.
    >
    Sure.

    <?php

    switch ($_SERVER['REMOTE_ADDR']) {
    case '143.3.5.1':
    header('Locatio n: BlueIndex.htm') ;
    break;
    case '124.6.15.7':
    header('Locatio n: RedIndex.htm');
    break;
    default:
    header('Locatio n: DefaultIndex.ht m');
    }
    ?>

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Skybuck

      #3
      Re: Serving a website based on source internet address ?

      <?php
      >
      switch ($_SERVER['REMOTE_ADDR']) {
      case '143.3.5.1':
      header('Locatio n: BlueIndex.htm') ;
      break;
      case '124.6.15.7':
      header('Locatio n: RedIndex.htm');
      break;
      default:
      header('Locatio n: DefaultIndex.ht m');
      }
      ?>
      Hello,

      Is it possible to use an "or" operator in php ? I only want to specific
      the location twice, since there are only two versions of the website.
      However there can be many ip's to include, for example in pseudo code:

      if (RemoteAddress = '192.5.6.7') or
      (RemoteAddress = '192.5.6.8') or
      (RemoteAddress = '192.4.6.8') or
      (RemoteAddress = '112.44.6.8') then
      begin
      header('Locatio n: RedIndex.htm');
      end else
      begin
      header('Locatio n: BlueIndex.htm') ;
      end;

      Is this possible in PHP ?

      Bye,
      Skybuck.

      Comment

      • Skybuck

        #4
        Re: Serving a website based on source internet address ?


        Skybuck schreef:
        <?php

        switch ($_SERVER['REMOTE_ADDR']) {
        case '143.3.5.1':
        header('Locatio n: BlueIndex.htm') ;
        break;
        case '124.6.15.7':
        header('Locatio n: RedIndex.htm');
        break;
        default:
        header('Locatio n: DefaultIndex.ht m');
        }
        ?>
        >
        Hello,
        >
        Is it possible to use an "or" operator in php ? I only want to specific
        the location twice, since there are only two versions of the website.
        However there can be many ip's to include, for example in pseudo code:
        >
        if (RemoteAddress = '192.5.6.7') or
        (RemoteAddress = '192.5.6.8') or
        (RemoteAddress = '192.4.6.8') or
        (RemoteAddress = '112.44.6.8') then
        begin
        header('Locatio n: RedIndex.htm');
        end else
        begin
        header('Locatio n: BlueIndex.htm') ;
        end;
        >
        Is this possible in PHP ?
        I'd still like to know the answer to this one ;) I tried the "or"
        operator but it doesn't seem to work.

        I think I found the solution looking at your post, the same effect can
        probably be achieved with a case fall through. Leaving the break out
        could achieve this effect if php is a case-fallthrough-language ;)

        I shall try this code next:

        <?php
        switch ($_SERVER['REMOTE_ADDR']) {
        case '143.3.5.1':
        case '142.3.5.1':
        case '146.3.7.1':
        case '141.3.5.1':
        case '123.7.5.10':
        header('Locatio n: BlueIndex.htm') ;
        break;
        case '124.6.15.7':
        header('Locatio n: RedIndex.htm');
        break;
        }
        ?>

        Bye,
        Skybuck.

        Comment

        • Jerry Stuckle

          #5
          Re: Serving a website based on source internet address ?

          Skybuck wrote:
          >><?php
          >>
          > switch ($_SERVER['REMOTE_ADDR']) {
          > case '143.3.5.1':
          > header('Locatio n: BlueIndex.htm') ;
          > break;
          > case '124.6.15.7':
          > header('Locatio n: RedIndex.htm');
          > break;
          > default:
          > header('Locatio n: DefaultIndex.ht m');
          > }
          >>?>
          >
          >
          Hello,
          >
          Is it possible to use an "or" operator in php ? I only want to specific
          the location twice, since there are only two versions of the website.
          However there can be many ip's to include, for example in pseudo code:
          >
          if (RemoteAddress = '192.5.6.7') or
          (RemoteAddress = '192.5.6.8') or
          (RemoteAddress = '192.4.6.8') or
          (RemoteAddress = '112.44.6.8') then
          begin
          header('Locatio n: RedIndex.htm');
          end else
          begin
          header('Locatio n: BlueIndex.htm') ;
          end;
          >
          Is this possible in PHP ?
          >
          Bye,
          Skybuck.
          >
          Did you try looking this up in the manual?

          Yes, it is possible - see
          http://www.php.net/manual/en/languag...rs.logical.php.

          But your problem is in how your if statement is constructed. See



          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Norman Peelman

            #6
            Re: Serving a website based on source internet address ?

            "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
            news:E8WdnQrOCr CsUGjZnZ2dnUVZ_ oednZ2d@comcast .com...
            Skybuck wrote:
            ><?php
            >
            switch ($_SERVER['REMOTE_ADDR']) {
            case '143.3.5.1':
            header('Locatio n: BlueIndex.htm') ;
            break;
            case '124.6.15.7':
            header('Locatio n: RedIndex.htm');
            break;
            default:
            header('Locatio n: DefaultIndex.ht m');
            }
            >?>

            Hello,

            Is it possible to use an "or" operator in php ? I only want to specific
            the location twice, since there are only two versions of the website.
            However there can be many ip's to include, for example in pseudo code:

            if (RemoteAddress = '192.5.6.7') or
            (RemoteAddress = '192.5.6.8') or
            (RemoteAddress = '192.4.6.8') or
            (RemoteAddress = '112.44.6.8') then
            begin
            header('Locatio n: RedIndex.htm');
            end else
            begin
            header('Locatio n: BlueIndex.htm') ;
            end;

            Is this possible in PHP ?

            Bye,
            Skybuck.
            >
            Did you try looking this up in the manual?
            >
            Yes, it is possible - see
            http://www.php.net/manual/en/languag...rs.logical.php.
            >
            But your problem is in how your if statement is constructed. See
            >
            http://www.php.net/manual/en/languag...-structures.if
            >
            >
            How about 'in_array()'?

            $ip_arr = array('192.5.6. 7',
            '192.5.6.8',
            '192.4.6.8',
            '112.44.6.8'
            );
            if (in_array($_SER VER['REMOTE_ADDR'], $ip_arr))
            {
            header('Locatio n: RedIndex.htm');
            }
            else
            {
            header('Locatio n: BlueIndex.htm') ;
            }

            .... not sure if you need to use the full domain name in the header function
            or not.

            Norm


            Comment

            Working...