Jump to content

Recommended Posts

Is there any way I could make php act as a browser and send a form post to a url for authentication. I want to do this so I can access and read a page within the site using php.

 

I have the reading bit already done. Now I am trying to see if I can authenticate php or the server into a specific website to access more content within the site.

Link to comment
https://forums.phpfreaks.com/topic/145681-authentication-from-server-to-website/
Share on other sites

Ok, I have the curl form post going to the site and I have a function the collects info within a div on a page withing the site. But, I cannot figure out how to combine the two. Or use authentication with the info collecting function.

//create array of data to be posted
$post_data['__VIEWSTATE'] = 'dDwfY6SxT5gIvWIKozYf=';
$post_data['UcLoginPage1:tbUsername'] = '4f6';
$post_data['UcLoginPage1:tbPassword'] = 'f6';

//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//create cURL connection
$curl_connection = curl_init('http://www.sfif.com/Login.aspx?HTTPReferer=Login.aspx?HTTPReferer=&Login=Error');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);

//close the connection
curl_close($curl_connection);



$item = "OP3f33";

// get DOM from URL or file
$html = file_get_html("http://smife.com/DAfil.aspx?Itefo=$item");

// find all div tags with id=gbar
foreach($html->find('div#price') as $e)
  { $num= $e->innertext;}
		$new_num = preg_replace ('~[^0-9.]~','', $num);
			$margin_num=$new_num*1.15;


			// find all div tags with id=gbar
foreach($html->find('div#qoh') as $e)
  { $qoh= $e->innertext;}

			echo "Original: $new_num<br />Margin: $margin_num<br />QOH: $qoh";
/*if($margin_num==0)
{  }
	else {mysql_query("UPDATE BOOKS set `price` = $margin_num WHERE `isbn` =$item", $db);}
*/

 

 

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.