darkfreaks Posted January 20, 2010 Share Posted January 20, 2010 okay how would i create a script using file_get_contents() in php have it grab search pages 1-20 and return the results based on whatever username was typed into the form. liek for example i would type "thisismyusername" and it would check all search pages for that exact username and if it came up empty to return "sorry, no username has been found matching this username" or else return "the username so and so has been found" the search url is this: http://vampirefreaks.com/gothicresults.php?pg=1&sex=male&sortby=user_datejoined and you can manually enter the page or change it by changing the pg= variable Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/ Share on other sites More sharing options...
teamatomic Posted January 20, 2010 Share Posted January 20, 2010 Why not use the advanced feature of the site profile.php?user={insert_user_name_here} HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999027 Share on other sites More sharing options...
darkfreaks Posted January 20, 2010 Author Share Posted January 20, 2010 oh i got it now thanks but how would i set it up? like give me an example. this is what i got so far: <?php $username=strip_tags(mysql_real_escape_string($_POST['username'])); $paedo=file_get_contents("http://vampirefreaks.com/profile.php?user=$username"); ?> how do i make it so it returns if the username exists or not? Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999038 Share on other sites More sharing options...
darkfreaks Posted January 20, 2010 Author Share Posted January 20, 2010 <?php $username=strip_tags(mysql_real_escape_string($_POST['username'])); $paedo=file_get_contents("http://vampirefreaks.com/profile.php?user=$username"); ?> how do i make it so it returns if the username exists or not? sorry i ran out of time to edit it LOL Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999044 Share on other sites More sharing options...
teamatomic Posted January 20, 2010 Share Posted January 20, 2010 <?php $url='http://vampirefreaks.com/profile.php?user='; $user='Mattykins'; $file = file_get_contents("$url$user"); echo "$file"; ?> note: this will display the page in your web browser, you will have to parse the users data out of $file. You should also input a fake user so you can see what gets returned so you can tell the diff. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999046 Share on other sites More sharing options...
teamatomic Posted January 21, 2010 Share Posted January 21, 2010 OK. $file will return the page in a string. you need to look at the source of the page(use your browser) and see how it is formatted. You should also put in a username like '2d4gstfg5gafj' or some other gobbly gook that you know is not a real user and see what is returned. You then will need to make a preg_match to get the users data. The page output looks well commented so it will be that difficult. Once you have the block you desire put it into an array by exploding the \n then go through and strip the html tags and drop enmpty lines. You should end up with lines like: Sex: male Age: 19 Location: Melbourne, Victoria, Australia HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999066 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 is there a more easier way just to match a few text phrases on the page? like "user has been deleted by VF admin For:" or "This user has Been suspended by vf admin for:" and if it matches to return "this user has Been Deleted/Suspended" Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999079 Share on other sites More sharing options...
teamatomic Posted January 21, 2010 Share Posted January 21, 2010 Just on a quick perusal of the returned page(s) from the advanced menu option all data is on a seperate line. So to do this easy and search through just use file() instead of file_get_contents then remove empty lines and strip the html tags then filter the lines you want to look for as you loop through the array. Use 'if' to filter then you can format your response and just output it. Or use file_get_contennts and do a preg_match for all the things you might find and format a response from that. Either way you have to do a bit of work, if it was 'real easy' everyone would be able to do it and no one would need sites like this. But what you are trying to do is fairly trivial once you get some experience under your belt and you will be able to bang something like that out from start to finish in about 1/2 hour, debugging and all. HTH Teamatomic HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999088 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 <?php $user=$_POST['user']; if(empty($user)){ ?> <form method="post"> <input type="text" name="user"> <input type="submit" name="submit" value="Assimilate!"> </form> <?php }else{ $url='http://vampirefreaks.com/profile.php?user='; $user=$_POST['user']; $file = file_get_contents("$url$user"); $pattern[0] = 'THIS USER HAS BEEN DELETED BY VF ADMIN Reason for Deletion:'; $pattern[1] ='This User Has Been Suspended by VF Admin for:'; if(preg_match($pattern,$file)){ echo "<font color=red>This User has Either Been Deleted or Suspended!</font>";} echo $file; } ?> it does not match why? Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999090 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 been tinkering around new code: <?php $user=$_POST['user']; if(empty($user)){ ?> <form method="post"> <input type="text" name="user"> <input type="submit" name="submit" value="Assimilate!"> </form> <?php }else{ $url='http://vampirefreaks.com/profile.php?user='; $user=$_POST['user']; $file = file_get_contents("$url$user"); $pattern[0] = '<center><hr><h3>THIS USER HAS BEEN DELETED BY VF ADMIN<br> Reason for Deletion: </h3></h3><hr></center>'; $pattern[1] ='<center><table border=4 bordercolor=white bgcolor=black width=100%><tr align=center><td><font color=red><h3>This User Has Been Suspended<br>by VF Admin for: </h3></font></td></tr></table></center>'; if(preg_match($pattern,$file)){ echo "<font color=red>This User has Either Been Deleted or Suspended!</font>";} else{ echo'<form method="post"> <input type="text" name="user"> <input type="submit" name="submit" value="Assimilate!"> </form> <font color=red>This user has been suspended/deleted By VF Admin!</font>'; } } ?> however now it just says everyone has been deleted or suspended it really isnt matching Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999103 Share on other sites More sharing options...
MadTechie Posted January 21, 2010 Share Posted January 21, 2010 Thats not a valid RegEx Pattern, maybe try stripos instead Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999112 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 tried stripos() it pretty much bypasses it now and just echoes the userpage <?php $user=$_POST['user']; if(empty($user)){ ?> <form method="post"> <input type="text" name="user"> <input type="submit" name="submit" value="Assimilate!"> </form> <?php }else{ $url='http://vampirefreaks.com/profile.php?user='; $user=$_POST['user']; $file = file_get_contents("$url$user"); $pattern = '<center><hr><h3>THIS USER HAS BEEN DELETED BY VF ADMIN<br> Reason for Deletion: </h3></h3><hr></center>'; $pattern2 ='<center><table border=4 bordercolor=white bgcolor=black width=100%><tr align=center><td><font color=red><h3>This User Has Been Suspended<br>by VF Admin for: </h3></font></td></tr></table></center>'; if(stripos($file,$pattern)){ echo "<font color=red>This User has been Deleted!</font>";} if(stripos($file,$pattern2)){ echo "<font color=red>This User has been Suspended!!</font>";} else { echo $file;} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999116 Share on other sites More sharing options...
teamatomic Posted January 21, 2010 Share Posted January 21, 2010 Maybe this will give you a hint as to what ot do and what is going on: <?php $url='http://vampirefreaks.com/profile.php?user='; $user='mojoblojowammo'; $file = file("$url$user"); foreach($file as $lines) { $line=strip_tags($lines); $line=trim("$line"); if ($line != ''){ echo "$line<br>\n"; if($line == 'THIS USER DOES NOT EXIST'){$message='this user is dead';} } } if ($message) { echo "<font color=red>$message</font>";} else{ echo'<form method="post"> <input type="text" name="user"> <input type="submit" name="submit" value="Assimilate!"> </form> <font color=red>This user has been suspended/deleted By VF Admin!</font>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999119 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 i switched to file() and it works now but it also shows in text form all the css and html ??? Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999123 Share on other sites More sharing options...
teamatomic Posted January 21, 2010 Share Posted January 21, 2010 Comment out the echo statement in the foreach. It is there for educational and debugging purposes. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999124 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 one last thing how would i edit in something like <?php if($line == 'THIS USER HAS BEEN DELETED BY VF ADMIN'){$message='This User Has Been Deleted!';} ?> tried it got nothing Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999138 Share on other sites More sharing options...
teamatomic Posted January 21, 2010 Share Posted January 21, 2010 If you leave the echo uncommented can you see the line you are trying to filter. Thats part of the echo, debugging. If you cant see the lines how can you know the one you are trying to filtering is even contained in the page you got and then how can you debug the code? Leave the echo on and can you see the line you are filtering on? HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999143 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 i took it off and pasted the exact message into the code and it still doesnt work should i use elseif instead of multiple if's? Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999149 Share on other sites More sharing options...
teamatomic Posted January 21, 2010 Share Posted January 21, 2010 Sounds as if you added it after the ending bracket for the forst if or foreach. if ($line != ''){ echo "$line<br>\n"; if($line == 'THIS USER DOES NOT EXIST'){$message='this user is dead';} //next if goes here#if($xxx){$message='xxx';} //next if goes here#if ($yyy){$message='yyy';} } } I would use multiple ifs, I find it easier to stack($message.='yyy<br>' messages. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999152 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 that is however not the case :'( <?php foreach($file as $lines) { $line=strip_tags($lines); $line=trim("$line"); if ($line != ''){ //echo "$line<br>\n"; if($line == 'THIS USER DOES NOT EXIST'){$message='This user is dead!';} if($line == 'THIS USER HAS BEEN DELETED BY VF ADMIN Reason for Deletion: pervert'){$message='This User Has Been Deleted!';} if($line == 'THIS USER HAS BEEN DELETED BY VF ADMIN Reason for Deletion:'){$message='This user has Been Deleted!!';} } } ?> All i get is a blank page cept for the first if Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999153 Share on other sites More sharing options...
teamatomic Posted January 21, 2010 Share Posted January 21, 2010 Give me the username of a banned pervert so I can see the results ... I tried darkfreaks but it didnt come back as a pervert...what gives ) HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999157 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 http://vampirefreaks.com/Viamund_the_Rake i have no idea Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999158 Share on other sites More sharing options...
teamatomic Posted January 21, 2010 Share Posted January 21, 2010 OK. If you look at the page you see THIS USER HAS BEEN DELETED BY VF ADMIN then the next line has the reason. You need to filter on: THIS USER HAS BEEN DELETED BY VF ADMIN then capture the next line as the reason. fairly simple. if($line=='THIS USER HAS BEEN DELETED BY VF ADMIN') { $reason = next($file);//gets the next pointer in the array $message="THIS USER HAS BEEN DELETED BY VF ADMIN::$reason"; } HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999159 Share on other sites More sharing options...
darkfreaks Posted January 21, 2010 Author Share Posted January 21, 2010 stilll doesnt work but when i do user is dead it loops everything over and over? should i move the last if outside the loop? Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999168 Share on other sites More sharing options...
teamatomic Posted January 21, 2010 Share Posted January 21, 2010 For some reason that lline contains a bunch of extra spaces. I added a preg_replace to replace all multiple spaces wtih one. Here is the code. at the bottom you will notice I have a commented out preg_match. you can use this to match part of a line if needed. <?php $url='http://vampirefreaks.com/profile.php?user='; $user='Viamund_the_Rake'; $file = file("$url$user"); foreach($file as $lines) { $line=strip_tags($lines); $line=trim("$line"); if ($line != ''){ $line=preg_replace('/\s+/',' ',$line); echo "$line<br>\n"; if($line == 'THIS USER DOES NOT EXIST'){$message='this user is dead';break;} if ($line == 'THIS USER HAS BEEN DELETED BY VF ADMIN Reason for Deletion:') {$message="$line $user";} } } if ($message) { echo "<font color=red>$message</font>";} else{ echo'<form method="post"> <input type="text" name="user"> <input type="submit" name="submit" value="Assimilate!"> </form> <font color=red>This user has been suspended/deleted By VF Admin!</font>'; } //if (preg_match("/THIS USER HAS BEEN DELETED BY VF ADMIN/i","$line")) ?> Quote Link to comment https://forums.phpfreaks.com/topic/189215-using-file_get_contents/#findComment-999174 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.