the in_array test bit doesnt work
probably because it does not test if submitted string is a part of total line in array(x)
as I mentioned it does not work
it is this test we should change
if (!in_array( $newadserver. "\r\n", $wordarray, TRUE )) { // word not already there
because one line
$wordarray[0] is "127.0.0.1 website.com\r\n"
and
$newadserver = "website.com"
so test is done if
"127.0.0.1 website.com\r\n" = "website.com\r\n"
and it is not
we should use a test for if "website.com" is a part within of any line ( $wordarray[x] ) in database.txt
we should need some help
i am no good with these string functions
but I will test if this change will work
<?php
error_reporting(E_ALL);
$info = "";
if (isset( $_GET['newadserver']) ) {
// checking, and possibly adding a new Ad servers
$newadserver = trim( $_GET['newadserver'] );
$newadserver = stripslashes($newadserver);
$newadserver = strip_tags($newadserver);
if ($newadserver == "")
$info .= "<h4>You tried to enter a blank entry</h4>";
else {
$blockedServers = array("localhost", "www.yahoo.com", "www.google.com");
if ( in_array( $newadserver, $blockedServers ))
$info .= "<h4>Sorry, \"$newadserver\" is blocked.</h4>";
}
if (empty( $info )) {
$file = "database.txt"; // database message file
$wordarray = file($file);
foreach ( $wordarray as $line ) {
if ( strstr( $line, $newadserver ) ) {
$info .= "<h4>The server \"$newadserver\" already exists in the vast Adserver database</h4>";
break; // jump out of foreach loop
}
}
}
if (empty( $info )) { // All is well, save newadserver
$fd = fopen($file, "a+");
fputs( $fd, "127.0.0.1" . " " . $newadserver. "\r\n" );
fclose ($fd);
$info .= "<h4>The server \"$newadserver\" was added to the database</h4>";
}
} //end of add new adserver process
//open wordlist file
$file = "database.txt"; // words file
$words = file($file); // put each word in the array
$list="";
if (isset($_GET['list'])) $list = $_GET['list'];
$word = "";
$word_number = 0;
$word_count = count($words);
if ($word_count) {
// if (!isset($message)) {
$word_number = rand( 1, $word_count ); // show a random message
// } else {
// $word_number = $message; // show requested message
// }
$word = $words[$word_number-1]; // position in array is $word_number-1
$word = ereg_replace("\n", "", $word);
}
// here comes HTML code
// Begin HTML output
?>
might work.
might not, but in such case, sure should be easy to fix
by some of our more experienced friends around here
As you can see $info is not only used for display information
but also serve as a variable, that signals, if everything is okay or not
and used like
if ( empty( $info ) ) do this
I prefer this, before creating another variable
or do some complicated if (this && that || not this)
that tells if things should be done
another thing I noticed
was you do not have anywhere in form an <INPUT
where $message ( $word_number ) get a value
so, will always be a random website shown
I commented that code out, but you may want to use it
about function [man]strstr[/man] in php manual
this is about the only in-string function I use
an example
/****
say we want to test what sort of files we have in a directory
if files has this or that extension: .exe .php .txt .dat ...
maybe list only all text files
****/
// do a loop and test every file like this
if ( strstr( $filename, ".txt" ) ) echo "$filename <br>";
// will produce a list of all textfiles, but no other files
/halojoy - gone testing his new strstr adserver code now
🆒