View Full Version : Disallow URLs PHP


starlet
08-13-2004, 03:01 PM
Is it possible to tell my plugboard script to block URLs...that way i could disallow some hosts that dont allow direct linking for example, but most importantly i can block the site of a person who i dont want to be using my plugboard, so when they type in their URL it'll say 'sorry, but domain.com is not allowed' or whatever!

Ive had a quick look myself, its not something i know how to do without a tutorial or at least a starting block and i dont really know what im searching for so i dont know where to start!

Any help appreciated.

briankircho
08-15-2004, 12:24 AM
I quickly added something for you. Let me know if it works...

<?
//#########################
//SETTINGS
//#########################
$font = "tahoma"; //Font used to display plugs
$fontsize = "1"; //Font size used to display plugs
$fontcolor = "000000"; //Font color used to display plugs
$bgcolor = "ffffff"; //Background color
$bordercolor = "ffffff"; //Bordercolor of the input boxes and button
$tablewidth = "88"; //Width of the plugboard's table
$maxdata = "10"; //Maximum plugs to show on the list at one time
$maxchars = "300"; //Maximum number of characters a person is allowed to use for their button url
$blocked = Array('http://blocked1.com/image1.gif','http://blocked2.com/image1.gif'); // These URLS are not allowed

//################################################## ############################
//SETTINGS END. DO NOT EDIT BELOW THIS LINE UNLESS YOU HAVE PHP SKILLS!
//################################################## ############################
if($action == "plug")
{
//SAVE PLUG
if ($url == "" || $url == "http://" || $sitename == "sitename" || $sitename == ""){die("<font face=$font><center>Error: one of the fields you submitted are invalid, please hit your back button and try again</center>");}

if((in_array($url, $blocked))
{die("<font face=$font><center>Sorry, but this domain is not allowed</center>");}

$savefile = "plug.db.php";
if (!file_exists($savefile))
{
$newfile = fopen($savefile,"w+");
fclose($newfile);
}
$ip = gethostbyname($REMOTE_ADDR);
$url = ereg_replace('<([^>]|\n)*>', '', $url);
$sitename = ereg_replace('<([^>]|\n)*>', '...', $sitename);
$lines = file("$savefile");
$add = "<?die ('Access unempowered')?>|$url|$sitename|$ip|";
$openfile = fopen("$savefile","w");
fwrite($openfile, "$add\n");
for ($i = 0; $i < $maxdata; $i++)
{
@fwrite($openfile, "$lines[$i]");
}
fclose($openfile);
echo "<script language=\"JavaScript\">window.location='index.php'</script>";
}
else
{
//SHOW PLUGS
echo
<<<HTML
<table width=$tablewidth cellspacing=0 cellpadding=0 style="border: none #$bordercolor; background-color: #$bgcolor;" >
<td>
HTML;
$openfile = file("plug.db.php");
$total = count($openfile);
for ($i=0; $i<$maxdata; $i++):
list($UNEMPOWERED,$url,$sitename,$ip) = explode('|',chop($openfile[$i]));
$url = str_replace("http://","",$url);
$sitename = str_replace("=","",$sitename);
echo "<a href=http://$url target=_new title=$url><img src=$sitename border=0 width=88 height=31></a><br>\n";
endfor;
echo <<<HTML
<form method='post' action='plug.php?action=plug' name='plug'><input maxlength='$maxchars' value='Button' type='text' name='sitename' size='20' style='font-family: $font; color: #$fontcolor; font-size: 7pt; background-color: #eeeeee; font-weight: none; border: 1px solid #$bordercolor'>
<input value='http://' type='text' name='url' size='20' style='font-family: $font; color: #$fontcolor; font-size: 7pt; background-color: #eeeeee; font-weight: none; border: 1px solid #$bordercolor'>
<input type='submit' size='30' value='plug' style='background-color: #eeeeee; font-family: $font; color: #$fontcolor; font-size: 7pt; border: 1px solid #$bordercolor'></form></td><tr></tr>
<td align="center" style="border-top: 1px solid #$bordercolor"><!--This link may be removed--><a href="http://www.``````````````" target="_blank">smw.com</a></td></table>
HTML;
}
?>

starlet
08-15-2004, 12:35 AM
muhaha you star! There was a slight error but it was easily fixed (double quote thingy at the start of line 22, only wanted a single one!) but that works just great, been having a real hard time with someone spamming it and i couldnt ban the ip address!

http://www.``````````````/testplug/index.php

Now when they try put in the domain name (slicedoranges.com) they shouldnt be able to! Thanks again, id have never worked it out on my own :)