-
[RESOLVED] help plase
Can anyone help me please.
im trying to show my site to people that are not banned from my website the html part at the top should only show when they are not banned and if they are banned then it show display the php you are banned code. When they are banned it still shows the html coade part aswell.
PHP Code:
<B>Website Coming Soon</b>
<?php
include("config.php");
mysql_connect("$host", "$username", "$password");
mysql_select_db($db) or die(mysql_error());
$sql = "SELECT * FROM ip";
$result = mysql_query($sql);
$row = mysql_fetch_array($result) or die(mysql_error());
if ($_SERVER["REMOTE_ADDR"] == $row["ip"] )
{
echo "You are banned from viewing this website";
}
?>
-
Re: help plase
PHP Code:
<?php
include("config.php");
mysql_connect("$host", "$username", "$password");
mysql_select_db($db) or die(mysql_error());
$sql = "SELECT * FROM ip";
$result = mysql_query($sql);
$row = mysql_fetch_array($result) or die(mysql_error());
if ($_SERVER["REMOTE_ADDR"] == $row["ip"] )
{
echo "You are banned from viewing this website";
}
else
{
?>
<b>Website Coming Soon</b>
<?php
}
?>
If you put the HTML at the top, it will show no matter what the PHP code is after that. What you want is either print the banned message or else (from the if banned statement) print the other message :)
-
Re: help plase
I need to show my website to the people that are not banned and show the You are banned from viewing this website message to people that are on my banned list?
-
Re: help plase
Doesn't that work? If instead of the <b>Website Coming Soon</b> part you put the code of your website?
PHP Code:
<?php
include("config.php");
mysql_connect("$host", "$username", "$password");
mysql_select_db($db) or die(mysql_error());
$sql = "SELECT * FROM ip where `ip` = '".$_SERVER["REMOTE_ADDR"]."'"; //select only the entries where the ip field matches the ip of the current user
$result = mysql_query($sql) or die(mysql_error()); //execute the query
if (mysql_num_rows($result) > 0) //if at least one row was returned from the query, in other words the IP was in the list, print the message and stop loading the page
{
die("You are banned from viewing this website");
}
?>
load website normally here.
If the IP is found in the table the the die function will run, printing the message and not loading the rest of the page.
Of course, I just noticed that you either have to loop through the IPs you select or add a where clause to your SQL statement to check for the IP.
Edit: I changed your SQL statement. I haven't tested it, I just typed it here, but I think it should work...
-
Re: help plase
I have tryed
PHP Code:
<?php
include("config.php");
mysql_connect("$host", "$username", "$password");
mysql_select_db($db) or die(mysql_error());
$sql = "SELECT * FROM ip";
$result = mysql_query($sql);
$row = mysql_fetch_array($result) or die(mysql_error());
if ($_SERVER["REMOTE_ADDR"] == $row["ip"] )
{
die("You are banned from viewing this website");
}
?>
load website normally here.
if the ip isnt banned then it shows a blank page.
-
Re: help plase
Have a look at my edits above :)
-
Re: help plase
yeah works now but will this work when i add more ip address's?
Also how do i make a page for me to add ip's to the database.? I have been struggling on it?
-
Re: help plase
-
Re: help plase
please DO NOT bump threads.
also, using die() is not good practice. I forget why, but i think it has to do with running process, and your stopping them in the middle. so dont do it.