Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP if function not working

Status
Not open for further replies.

1gbram

Technical User
Jul 1, 2006
69
GB
I'm working on a website, that, when visited, will list the users IP and a GET command (which is their username) and save it to a text file.

Then when another page is visited, will use another GET funtion, then go through the text file, line by line, and find a match between their GET username and a line of the file. This page will then send every other name and IP to another file, wipe the first one, then cop the contents of the second in the first, thus deleting that GET and thier IP.

The first part works, but the second part (not fished) doen't.
So far the second file consits of this:
Code:
<?PHP
$myFile = "pplonline.txt";
$brbr = "<br>";
$fh = fopen($myFile, 'r');
$myusr = $_GET['usr'];
echo $myusr;
echo "<BR>";
for ( $counter = 1; $counter <=25; $counter +=1){
		
	
	$ip = fgets($fh);
	$usr = fgets($fh);
	echo $usr;
	if ( $usr == "USEr" ) {
		echo "Your user";
	} else {
		echo "NOT print to ppl2";
		
	}
	echo "<BR>";
}
fclose($fh);
the usernames /names in this file are edited
but when viited brings up :
Code:
morgs
GETvalue1 NOT print to ppl2
GETvalue2 NOT print to ppl2
GETvalue3 NOT print to ppl2
GETvalue4 NOT print to ppl2
NOT print to ppl2
etc. etc.
(GETvalue's were edited, on the file they show the atual values)
ppl2 is the second username file

I will try and get some example on the web for you to see for yourselves soon
 
you might find it better to use a set of parallel arrays and search for users by using in_array. but in the meantime try this approach instead. i believe that yours was not working due to the appending of new line characters.

Code:
<?php
$myFile = "pplonline.txt";
$brbr = "<br/>";
//bring file into an array
$lines = file($myFile,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

$myusr = trim($_GET['usr']);

$numLines = count($lines);
$counter = 0;
while ($counter < $numLines){
	$data[] = array(	'ip'=>$lines[$counter],
						'userName'=>$lines[$counter+1]);
	if ( $usr == "USEr" ) {
	    echo "Your user";
	} else {
	    echo "NOT print to ppl2";
	}
	echo $brbr;
	$counter = $counter + 2;
}
echo "<pre>".print_r($data,true)."</pre>";
?>
 
silly question but why?
surely a database would be better suited to this type of functionality?
 
Becasue of the host i'm using; they offer MySQL for money, and ban the file type if otherwise.
And because of the way it's used; i'm using Python to get the website, so it sivethe IP without using a browser
 
Ahh, A case of universal Plan B

"when all else fails cheat"

Good luck with geting your solution working
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top