2 Replies Latest reply on May 9, 2009 1:45 AM by pschaver

    How to restrict access to a page by IP using the login form wizard?

    pschaver

      Hi,

       

      I have build a website with various pages with restricted access using the login form wizard and the restrict access to folder control.

      Is it possible to check not only the username, password and access level, but also the user's IP address?

      Where to look for in the code to modify it.

       

      Thans in advance.

        • 1. Re: How to restrict access to a page by IP using the login form wizard?
          ShaneM09

          Hello,

           

          I don't think you can do this with the wizard. It would require some hand coded PHP to do, but it's not really too hard. One way to do it would be to setup a list of valid IP addresses in a database table. For those pages you want to restrict by IP address, you would add PHP code to the top of the page to check the users IP against your list in the database and then redirect them if thieir ip address does not match. Here's the basic steps:

           

          1. get IP address of user - check this link for info on how to do that: http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html

          at its most basic you can use $ip=$_SERVER['HTTP_CLIENT_IP']  but read up on the link for how to do a better ip check

           

           

           

          2. query your database table of IP addresses to see if it matches users ip = "SELECT * FROM ip_table WHERE ip_address = '$ip'

           

          3. if your query returns no rows of data, redirect the user to a unauthorized access page

          if($returnedRows == 0) { Header("Location: unathorized.php"); }

           

          This shouldn't be too hard to figure out, but it will take some hand coding and reading on your part to get it done.

           

          Hope this helps.

           

          Shane

          1 person found this helpful
          • 2. Re: How to restrict access to a page by IP using the login form wizard?
            pschaver Level 1

            Thank you very much for your quick reply, Shane.

            I will try to do this.

             

            Thanks,

             

            Paul