Thursday, August 5, 2010

URL push and URL pull to send / retrieve information between cross domains

Hello friend,
Today I have done a small but very useful functionality i.e URL push and URL pull means you can send information to remote url and retieve information from other url. Getting information is easy and i think all developers know it, but sending information is little tricky when we don't know how the post variable names.
Below is the code to track the post parameter names and values in targetsite.
//extract($_POST);
foreach($_POST as $key=>$value)
{
echo $key.'='.$value.'
';
}
echo $_SERVER['HTTP_REFERER'];
/*Output:
key = value
key = value
etc..,
http://from-site-name.com/filename
*/
?>
So here in foreach loop you will get the post param names and values. So you can store in db with table structure as id autoincrement, key, value, referrer,posted_on. OR use xml file to store the information in structured way like valuevalueetc..,

Ex: http://formsite-name.com/postinfo.php
##################################################################
form action="http://targetsite.com/getvalues.php" method="post"
Name:input type="text" name="name"
Address:input type="text" name="address"
Email:input type="text" name="email"
input type="submit" value="Submit"
/form
#####################################################################

When user submits the above form the remote script (i.e mentioned in form action will execute) here it is at http://targetsite.com/getvalues.php
//extract($_POST);
foreach($_POST as $key=>$value)
{
echo $key.'='.$value.'
';
}
echo $_SERVER['HTTP_REFERER'];
/*Output:
name = postedname
address = postedaddress
email = postedemail
http://formsite-name.com/postinfo.php
*/
?>