-
Posts
9,409 -
Joined
-
Last visited
-
Days Won
1
Everything posted by MadTechie
-
How to retrieve information from other websites and store?
MadTechie replied to jadoo1989's topic in Application Design
Yeah, your need to use cURL then, Here a function I wrote, for a basic login (was only for testing, but it works, I made a few tweak to run as a single function but it something to play with) <?php function Login() { $ch = curl_init('http://domain.com/users.php?act=login-d'); $ckfile = sys_get_temp_dir()."/CURLCOOKIE.txt"; curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); //Login curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'username'=>"My UserName", 'password'=>'My Password', 'login'=>'Login', 'remember'=>'0' ) ); curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); return $output; } ?> Login() will return the HTML found, you need to update the URL $ch = curl_init('http://domain.com/users.php?act=login-d'); and Fields curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'username'=>"My UserName", 'password'=>'My Password', 'login'=>'Login', 'remember'=>'0' ) ); Just view source and read the form from the HTML and build the array above to suite Okay I think you have everything needed.. So i will wish you luck, any problems just ask EDIT: and welcome to PHP Freaks:p -
How to retrieve information from other websites and store?
MadTechie replied to jadoo1989's topic in Application Design
Okay cool, remember we have a RegEx section here (subsection of PHP Help), as for cURL (you might get away with file_get_contents, here's a very quick and simple example <?php //Get Data form this page (no login required so no cURL needed) $data = file_get_contents("http://www.phpfreaks.com/forums/index.php/topic,260169.0.html"); //$data is the same as viewing source, if you view this source your see "action=profile;u=47001" and "action=profile;u=84706" these are the links to our profiles //Find text in between action=profile;u={any number}'> get data until I see a < preg_match_all('/action=profile;u=\d+\'>([^<]*)</', $data, $Users); $Users = $Users[1]; //display or insert found data foreach($Users as $User) { //INSERT INTO DATABASE echo "$User\<br />\n"; } ?> EDIT: added some comments -
well what do you mean by doesn't work ? what's $description set to ? also I would change strstr to stristr and str_replace to str_ireplace
-
How to retrieve information from other websites and store?
MadTechie replied to jadoo1989's topic in Application Design
For someone who's "quite new to PHP", this may not be the easiest thing, cURL: To connect to another site your need to use cURL (or fsocket) this allows you to post values (ie Username and password). RegEx: To extract the details your probably want to use Regular Expressions, MySQL: To store the details a simple database ie MySQL would work well as you could do a simple search to check to see if you have the data already. Now, if you are writing this to scrape data from one site it shouldn't be too much trouble (note: check T&C's to check your not breaking the rules), but your need to really look at the planning if you want it to work for multiple sites -
[SOLVED] PHP Help - Replacing Space with underscore in filenames
MadTechie replied to Gamerz's topic in PHP Coding Help
if you want the links updated as well you might as well just update the $filename variable before hand! $filename = str_replace(" ","_",$filename); if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename )) -
[SOLVED] PHP Help - Replacing Space with underscore in filenames
MadTechie replied to Gamerz's topic in PHP Coding Help
Point taken, would be nice if people who use PHP actual learn PHP, it won't work.. because thats the syntax on how to use str_replace! you would use it like this.. if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . str_replace(" ","_",$filename) )) -
[SOLVED] PHP Help - Replacing Space with underscore in filenames
MadTechie replied to Gamerz's topic in PHP Coding Help
on the filename you wish to change did you not write this code yourself ? // Upload the file to your specified path. if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) -
I'm glade this is solved
-
[SOLVED] PHP Help - Replacing Space with underscore in filenames
MadTechie replied to Gamerz's topic in PHP Coding Help
use str_replace(); -
Well u.id isn't in that statement So MySQL shouldn't give any message about u.id
-
change htmlentities( $code ); to echo htmlentities( $code );
-
Can you post the latest code
-
[SOLVED] HttpRequest / Response trouble.
MadTechie replied to severndigital's topic in PHP Coding Help
Goto the login form and view source, the action is the URL (of course your probably need to add the domain name) the fields will have names and values make sure the array has these, and that should be it -
If you say so.. theirs no way i could know thast with seeing the code!
-
[SOLVED] HttpRequest / Response trouble.
MadTechie replied to severndigital's topic in PHP Coding Help
Thats the URL.. thats where your submitting too! -
[SOLVED] HttpRequest / Response trouble.
MadTechie replied to severndigital's topic in PHP Coding Help
it depends on the form.. read the html form, yoy use to login get the fields and action.. and add them to the array -
Maybe worth noting Whats the timeout for the script.. if each site took 1 second and you had 60 sites, but your timeout was 30 then the script will timeout, with that inmind it may be worth adding set_time_limit(0); Also $var = file_get_contents($address, $context); should probably be something like $var = file_get_contents($address, $context); $values[] = ($var===false)?false:true;
-
Yes it is.. works for me Here's an idea maybe, if you give a little bit of useful information or here's an idea maybe post what you have and a description of what you want it to do and what it is or is not doing, you know considing we are spending time to help maybe a little bit of your time would be a valid investment
-
add error_reporting(E_ALL); to the start
-
[SOLVED] HttpRequest / Response trouble.
MadTechie replied to severndigital's topic in PHP Coding Help
$r->send() Sends the HTTP request. and Returns the received response as HttpMessage object. getBody() is an object that is returned that has the contents you could also do this $r->send(); echo $r->getResponseBody(); -
[SOLVED] HttpRequest / Response trouble.
MadTechie replied to severndigital's topic in PHP Coding Help
try this <?php $url = 'my.site.com'; $username = 'username'; $password = 'password'; $login = new HttpRequest($url. "/Login", HttpRequest::METH_POST); //The array Keys are the post keys $post_data = array("Username"=>$username,"Password"=>$password); $login->addPostFields($post_data); try { echo $r->send()->getBody(); } catch (HttpException $ex) { echo $ex; } ?> EDIT:updated to fit what you have -
turn on error reporting, its probably timed out
-
depending on how your code starts the maze.. you may want to change if(empty($_SESSION['pos'])) to if(!isset($_SESSION['pos'])) if your not setting before hand! I also this has moved a little out side the ranges of "design"
-
Erm... that doesn't help me much!