FaRmBoX Posted July 30, 2009 Share Posted July 30, 2009 I am running the php file of my localhost computer that has php installed. Problem: I am trying to "login" into a website and create a refresh loop that searches for a string in the "logged in" page. How do I login into the website and still keep my functions from my webpage running? (The search). The login page has a form that has inputs user_login, user_password, remember. Also, if I will have to use the websites cookies to stay logged in during my loop, how do I gather and use them? My Failure Solutions: I tried doing a header that link to the site and logs in through a javascript link. It did not work with the php header, I got no errors. I tried same thing putting the javascript link into an iframe. When I run through php CLI on my computer, it did not login.... But when I ran it on my webhosting, it DID login. And now im out of ideas. I need something that works like winsock for programs that sends and receives data from servers. Please help! This is giving me such a headache! Here is my code: Main file (loop file) code snippet: while(1) { if ($start == true) { include("read.php"); if ($found == true) { echo "YAY!"; } else echo "nay...."; } } read.php (the file that searches for text string in the different website webpage) <?php $url = 'http://website.com/members.php?id=64344'; $needle = 'welcome to our awesome site!'; $contents = file_get_contents($url); if(strpos($contents, $needle)!== false) { $found = true; } else { $found = false; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/168165-help-with-socket/ Share on other sites More sharing options...
FaRmBoX Posted July 30, 2009 Author Share Posted July 30, 2009 Any way I can use sockets? Quote Link to comment https://forums.phpfreaks.com/topic/168165-help-with-socket/#findComment-887053 Share on other sites More sharing options...
FaRmBoX Posted July 30, 2009 Author Share Posted July 30, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/168165-help-with-socket/#findComment-887237 Share on other sites More sharing options...
FaRmBoX Posted July 31, 2009 Author Share Posted July 31, 2009 bump... Can anyone help me? Quote Link to comment https://forums.phpfreaks.com/topic/168165-help-with-socket/#findComment-887878 Share on other sites More sharing options...
roopurt18 Posted July 31, 2009 Share Posted July 31, 2009 You can use the HttpRequest object. http://us3.php.net/manual/en/class.httprequest.php Create the object and make the initial POST request. When the request returns you'll want to find the session cookie that came with it and set that cookie value into the HttpRequest object. From then on out the HttpRequest object will send the session cookie with any future requests and the web site will think you're a regular user. <?php $http = new HttpRequest( 'http://www.somedomain.com/login.php', HTTP_METH_POST ); $http->addPostFields( array( 'username' => 'jonny5', 'password' => 't0p53c23t5' ) ); $http->send(); $cookies = $http->getResponseCookies(); foreach( $cookies as $cookie ) { $http->addCookies( $cookie->cookies ); } echo $http->getResponseBody(); // Just to see what was returned $http->setMethod( HTTP_METH_GET ); $http->setUrl( 'http://www.somedomain.com/listusers.php' ); $http->send(); echo $http->getResponseBody(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/168165-help-with-socket/#findComment-887952 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.