jakebur01 Posted February 18, 2009 Share Posted February 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145681-authentication-from-server-to-website/ Share on other sites More sharing options...
milesap Posted February 18, 2009 Share Posted February 18, 2009 Yes you can. Urlencode the username and password, then use cURL to create a connection with the other website. Quote Link to comment https://forums.phpfreaks.com/topic/145681-authentication-from-server-to-website/#findComment-764827 Share on other sites More sharing options...
jakebur01 Posted February 18, 2009 Author Share Posted February 18, 2009 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);} */ Quote Link to comment https://forums.phpfreaks.com/topic/145681-authentication-from-server-to-website/#findComment-764863 Share on other sites More sharing options...
jakebur01 Posted February 18, 2009 Author Share Posted February 18, 2009 bump.. Quote Link to comment https://forums.phpfreaks.com/topic/145681-authentication-from-server-to-website/#findComment-765271 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.