Very new, Very Simple

I’m new to the whole web page design thing. i’m trying to make a very simple script thats writes only unique entries to a txt file but i dont know how th disallow duplicates. i need to know how to do that. i would like the script as small and simple as possible and security is no issue as the data is not vital. also i need a script that redirects to a random page chosen from a line on a text file in a frame with an menu to change the delay time without repeating and pages. the second request i haven’t started on yet so i might be able to figure that out. in its entirety i dont want the script using anything but html, php, and js. no databases. heres what i got so far.

in folder “usrs”
“index.htm”
“usr.php”
“usr.txt”

usrs/index.htm

User: ================================================================= usrs/usr.php ------------------------------------------------------------------------------------------- <?PHP

header(“refresh: 3; url=http://localhost/usrs”);
$usrs = “usr.txt”;
$input = $_POST[‘usr’];

$usrp = fopen ($usrs, “a+”);
if ($usrp) {
fwrite ($usrp, “$inputrn”);
fclose ($usrp);
echo (“Database updated
Thank you for the submission.”);

}
else {
echo (“An error occurred and database was not updated”);
}

?>

usrs/usr.txt (examples only)

012345
123456
234567

The script works but i do not know how to disallow duplicate entries

This may help or it may not. I was trying to create a script that would search a file for an entry and then take the data from the entry and put in to use. The entry would be setup as “image.jpg:group:description” and would be thrown into an value as $string = ‘’; Where $tmp[0] is the imagename, $tmp[1] is the group, and $tmp[2] is the description. This function may be of use to you and it may not. I provide it as a way for you to search a file to see if an entry exists.
The file with the function:[code]<?php
function fileVar($arg1 = ‘’, $arg2 = ‘’, $arg3 = ‘:’){
// arg1 is the variable for file
// arg2 is the variable for search
// arg3 is the variable for seperator
$error1 = 0;
$error2 = 0;
// arg Checks
if($arg1 == ‘’){
echo “Error: File not set.
n”;
$error1 = 1;
}
if($arg2 == ‘’){
echo “Error: Search variable not set.
n”;
$error2 = 1;
}
// If $error1 and $error2 are not true do this.
if($error1 != 1 && $error2 != 1){
// Check to see if file exists.
if(!file_exists($arg1)){
echo “Error: Bad file supplied.
n”;
return;
} // End if
// Check to see if Search String exists
$chk = file_get_contents($arg1);
if(!strpos($chk, $arg2 . $arg3)) {
echo “Error: String not found!”;
return;
} // End if

$pfile = fopen($arg1,"r");
rewind($pfile);
while (!feof($pfile)) {
	$line = fgets($pfile);
	$tmp = explode($arg3, $line);
	if ($tmp[0] == $arg2) {
		$string = '<a href="'.$tmp[0].'"  rel="lightbox['.$tmp[1].']" title="'.$tmp[2].'"><img src="'.$tmp[0].'" /></a>';
		return $string;
	} // End If
} // End While

} // End If
return;
} // End Function

$tvar = “5”;
$file = “test.txt”;
$getData = fileVar($file, $tvar);
print_r($getData);

?>[/code]

The file test.txt that it calls:1:data1:data2 2:2data1:2data2 3:3data1:3data2 4:4data1:4data2 5:5data1:5data2 6:6data1:6data2 7:7data1:7data2

Hope this is of some use.

Why not just use file() and in_array()?

$myfilecontents = file("test.txt");
if (!in_array($myfilecontents, $mynewvar)) {
  // append your file with the new var
}
Sponsor our Newsletter | Privacy Policy | Terms of Service