8 Replies - 6474 Views - Last Post: 27 March 2009 - 06:59 PM Rate Topic: -----

#1 brawnyman713  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 139
  • Joined: 21-October 07

How do I have PHP login to a website?

Posted 22 December 2008 - 12:58 PM

So I'm doing this little project for a small business. This business buys it's products from three different distributors. All three distributors have a website where you can look up an item, see the quantity left and the cost of the item. What this script is supposed to do is take every item the business sells, and get the price and quantity left from all three businesses, and from that make a recommendation for which vendor should be used for each product (lowest price of the vendors that have inventory available).

The problem is that all three vendors will let you view that item page, but in order to see the price and the quantity you must be logged in. I know how to set up the database, how to set the script to run every so often, how to parse the webpage to get the relevant info, and how to decide what recommendation to make. What I don't know is how to make a PHP script act as a client. Are there any functions that let the script send POST data and act as a client?

This post has been edited by brawnyman713: 22 December 2008 - 02:29 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How do I have PHP login to a website?

#2 brawnyman713  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 139
  • Joined: 21-October 07

Re: How do I have PHP login to a website?

Posted 22 December 2008 - 02:35 PM

I should be a bit more clear. To have it act as a client, I need it to be able to request web pages, hold cookies, and send POST data
Was This Post Helpful? 0
  • +
  • -

#3 Hary  Icon User is offline

  • D.I.C Regular

Reputation: 44
  • View blog
  • Posts: 427
  • Joined: 23-September 08

Re: How do I have PHP login to a website?

Posted 22 December 2008 - 02:37 PM

You can create a socket to the other sites, and send http commands to them.

Best way to start is the HTTP Functions in PHP. Seee the PHP Manual

Please be aware this might not be allowed by the other website and will result in legal issues. Please consult them, they might have a nice (SOAP) web service on which you do not bother their front end systems.
Was This Post Helpful? 1
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6081
  • View blog
  • Posts: 23,558
  • Joined: 23-August 08

Re: How do I have PHP login to a website?

Posted 22 December 2008 - 02:52 PM

The built-in cURL library is another possibility.
Was This Post Helpful? 1
  • +
  • -

#5 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: How do I have PHP login to a website?

Posted 22 December 2008 - 03:04 PM

Yeah cURL will let you hold cookies and all that other tasty data. Just send the login information to the page's login form as a CURLOPT_POSTFIELDS variable, and you should be good to go.
Was This Post Helpful? 1
  • +
  • -

#6 brawnyman713  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 139
  • Joined: 21-October 07

Re: How do I have PHP login to a website?

Posted 22 December 2008 - 03:25 PM

This seems like exactly what I need. Thanks
Was This Post Helpful? 0
  • +
  • -

#8 zeldaze  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 14
  • Joined: 19-December 08

Re: How do I have PHP login to a website?

Posted 22 December 2008 - 05:05 PM

I posted the below script in another thread and I think it might be helpful in this case too. You'll just need to change the username and password and possibly modify the POST data further.

Enjoy.
<?php
// Set username and password values below...
$username = 'username';
$password = 'password';

// Initialize cURL
$ch = curl_init();

// Set the URL
curl_setopt($ch, CURLOPT_URL,"http://www.theubm.com/index.php");

// Accept cookies
curl_setopt($ch,CURLOPT_COOKIEFILE,1);

// Submit our POST values (EG: username and password)
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$username&password=$password");

// Execute...
$output = curl_exec($ch);


// Display the result
echo $output;
?>

Was This Post Helpful? 1

#9 brawnyman713  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 139
  • Joined: 21-October 07

Re: How do I have PHP login to a website?

Posted 23 December 2008 - 02:45 PM

Seriously, zeldaze. That is perfect. That's exactly what I needed. Thank you
Was This Post Helpful? 0
  • +
  • -

#10 beju0506  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 78
  • Joined: 23-February 08

Re: How do I have PHP login to a website?

Posted 27 March 2009 - 06:59 PM

View Postbrawnyman713, on 22 Dec, 2008 - 11:58 AM, said:

So I'm doing this little project for a small business. This business buys it's products from three different distributors. All three distributors have a website where you can look up an item, see the quantity left and the cost of the item. What this script is supposed to do is take every item the business sells, and get the price and quantity left from all three businesses, and from that make a recommendation for which vendor should be used for each product (lowest price of the vendors that have inventory available).

The problem is that all three vendors will let you view that item page, but in order to see the price and the quantity you must be logged in. I know how to set up the database, how to set the script to run every so often, how to parse the webpage to get the relevant info, and how to decide what recommendation to make. What I don't know is how to make a PHP script act as a client. Are there any functions that let the script send POST data and act as a client?



I don't have an answer to your question, but I had to comment, lol... I actually have a project exactly like this in my OOP class. However, we have to do it in Java... And it's a pain lol ;) Good luck! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1