FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Using URL API





eudbase
Hi, may I know whether PHP can use URL API given by some websites? The website that provides the URL API actually suggesting to use PERL but I am not very good at that too. If anyone do know how to use URL API by using PHP or PERL, please tell me how to do it. Thanks.
rvec
what kind of api and how does it work/what should it do?
eudbase
I intend to send a form data to another website`s application form. The website provides with a URL API service. What I don`t know is how to use PHP coding to make a HTTP request. I have found curl in PHP but I am not very clear about the manual... I need the basic source code to make a HTTP request using PHP.
rvec
you should find out if that's done with post or get. If you see all the data in the url it's done with post, else it's done with get.

Now you have to find out where the form is send to, this can be done by finding this part in the source of the form page (this part is from the frihost posting page):
Code:
<form action="posting.php" method="post"

This code said that the form uses post to send the data to posting.php.

Also we need the fieldnames so we know what the names of the post data have to be. This can also be found in the source between the <form> and </form> tag.
on this page:
Code:
<input type="text" name="subject"

Code:
<input type="button" class="button" accesskey="b" name="addbbcode0" value=" B "

more buttons
Code:
<select name="addbbcode18"

Code:
<input type="text" name="helpbox"

Code:
<textarea name="message"
<--the message itself
Code:
<input type="checkbox" name="disable_smilies"

Code:
<input type="hidden" name="mode" value="reply" /><input type="hidden" name="sid" value="973b57697195f497e864be339143663a" /><input type="hidden" name="t" value="93653" /><input type="submit" tabindex="5" name="preview" class="mainoption" value="Preview" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" accesskey="s" tabindex="6" name="post" class="mainoption" value="Submit" />


now we have to put all the data we want to send in an array like this:
Code:
$post_data = array('subject'=>'Using URL API', 'message'=>'message here', 'disable_smilies'=>'', 'mode'=>'reply', ..........);


If I wanted to send the post to frihost I had to be logged in first, I hope you don't have to because that makes it a bit more difficult.

To send the post data to frihost using the above information we can use this script:

Code:

$post_data = ......above array here ......
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.frihost.com/forums/posting.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

$index = curl_exec($ch);


I hope that helped a bit Smile


If you want to send GET data you can send it like this:
Code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.frihost.com/forums/posting.php?subject=testing&message=more%20testing");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$index = curl_exec($ch);

To get the fieldnames and see if it is get do the same as with post.
Related topics
Do you use a CMS script?
*OFFICIAL* Which Browser do you use?
How To : Secure Your PHP Website
I cant enter Frihost and my web site from home
[Official] Best PHP Editor
Are there any REALTORS using FriHost?
HTML Kit Tools, anyone using?
namecheap.com...masking url??
namecheap url problem
Question about operating systems?
POP3 with PHP
Error while setting avatar from URL
Paring JSON with PHP. Help!
Custom window interface like of iTunes,PowerDVD using win32
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.