Jump to content

Help with.... socket?


FaRmBoX

Recommended Posts

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!  :facewall:

 

 

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;
}
?>

Link to comment
Share on other sites

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();

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.