Showing posts with label addresses. Show all posts
Showing posts with label addresses. Show all posts

Thursday, June 30, 2016

IT Discussion in a Milist Script PHP for Blocking IP Addresses

Greetings,

I want to ask, whether or not if we develop or use a simple web (e.g. Joomla, etc) then  we could setup some specific public IP addresses to not access our website?
If getting traced or ping-ed it seems to be normal.

If someone could help,  I greatly thank you.


regards
-------------------------------------------------



It could, set it from its CPanel web / domain


regards
----------------------------------------------

OK thanks for your info ... but if getting traced or ping-ed it seems to be normal, so only  when getting accessed from a browser it couldnt be accessed.
However if we access using another connection then I think whether my public IP is getting blocked?

regards
-------------------------------------------

The most frequent occurrence as such is from speedy, probably because the user is speedy (with a specific IP address range) that send a lot of spam so that the IP address ranges included in the list of spam house, consequently if we want to access a particular web address using a speedy connection, then access will be blocked, whereas if you use the internet connection instead of speedy, the internet access runs normally.
The way that can be normal again, ask for a speedy person to realease your IP address or change the IP address.

regards
----------------------------------

if using php, write a simple script, for example in index.php
put it on top, for example

$ banned_ips = array (x.x.x.x, y.y.y.y, z.z.z.z);

if (in_array ($ _ SERVER [REMOTE_ADDR], $ banned_ips)) {
                 die ();
                  }
?>

where xxxx - zzzz, is the list of IP addresses that we will be ban

hopefully helpful

regards

Monday, June 13, 2016

Restricting admin page to be accessed from only certain ip addresses

If you want to apply someting more secure than just a password to access your admin page you can restrict your admin page to be accessed from only one ip address.

First you should know your ip address. If you dont know you can run this script: 
  <?php
  echo "IP anda : " . $HTTP_SERVER_VARS[REMOTE_ADDR];
?>

Then in the admin area, for example in "administrator/index.php", insert this script on the topmost:

<?php
  $ip = "127.0.0.1" // your ip
  if($HTTP_SERVER_VARS[REMOTE_ADDR] != $ip) {
  header("location: ../index.php");
  } else {
  Setcookie("ip",$ip); }
?>

Then for each file in the admin area, insert this script:

<?php
  $ip = $_COOKIE[ip]; // call cookie ip
  if($HTTP_SERVER_VARS[REMOTE_ADDR] != $ip) {
  echo "You dont have right to access this page!";
  } else {
  // your menu here
  }
?>

Please remember to call cookies or session for your admin username and pasword as well. The example above only call cookie for ip address. 

You may want to apply more than one ip address and store the ip address list in database as following:

CREATE TABLE `web`.`tb_admin` (
  `id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `ip` VARCHAR( 30 ) NOT NULL
  ) 
 
  INSERT INTO `web`.`tb_admin` (  `id` ,  `ip`  )
  VALUES (1 , 127.0.0.1);

Config.php
<?php
$host = "localhost";
$user = "root";
$pass = "";
$konek = mysql_connect($host,$user,$pass) or die("Check host,user,or password");
$select_db = mysql_select_db("web");
?>

Then in the index.php in the admin folder, you can insert this script:

index.php

<?php
  include("config.php");
  $ip = $HTTP_SERVER_VARS[REMOTE_ADDR];
  $valid_ip = mysql_query("SELECT * FROM tb_admin WHERE ip=$ip");
  if (!= $valid_ip) {
  echo "You dont have permission to access this page!";
  } else {
  // your menu goes here...
  }
?>