Examples » Introduction
In this article, I will show you how to write HTTP scripts to solve a particular task. The examples given will show you the power of phpWebHacks, and its simplicity for HTTP scripting.
While HTTP scripts are relatively short, it takes efforts to write one. Usually you'll do the task manually with your browser and do a lot 'view HTML source'.
Here's an example. Say you want to login to your webmail. First, open your webmail in your browser, e.g: http://webmail.example.com. Your browser will display the login page.

Fig 1. Login page
Now switch to your PHP editor and type the following:
include 'phpWebHacks.php';
$h = new phpWebHacks;
$page = $h->get('http://webmail.example.com');
Back to your browser, right click to view the HTML source to see the form's action URL and the name of the fields. It may looks something like this:
<body>
<form action="redirect.php" method="post">
<table bgcolor="#ffffff" align="center" border="0" width="100%">
<tr>
<td align="right" width="30%">Name:</td>
<td align="left" width="*">
<input type="text" name="login_username" value="" /> @
<select name="login_domain">
<option value="example.com">example.com
</select>
</td>
</tr>
<tr>
<td align="right" width="30%">Password:</td>
<td align="left" width="*">
<input type="password" name="secretkey" />
</td>
</tr>
</table>
<center><input type="submit" value="Login" /></center>
</form>
</body>
</html>
From the HTML source above, we find that the form's action is redirect.php, and the required fields are: login_username, login_domain, and secretkey. Switch to your HTTP script, 'fill in' your username and password, then login.
$form['login_username'] = 'myusername';
$form['login_domain'] = 'example.com';
$form['secretkey'] = 'mypassword';
/* login */
$page = $h->post('redirect.php', $form);
The code above will return the HTML page for the authorized user, usually it is your inbox page. From this point, you can go to any page by requesting their URLs. Again, obtain the URLs from the HTML source.
The process is not easy for the first time, and you have to put a lot of efforts before getting a working script. But you'll get used to and it'll be a lot easier later. Here are more examples:
Grabbing GMail Contact List