how to make web call to other website using php

There are many way to get around with cross site scripting.
When you want to make call to other website or other domain, there is limitation of javascript which does not allow to cross-site scripting.
When you try to make call you usually end up getting following error message.

“not allowed by Access-Control-Allow-Origin”

However, there is a solution to this problem, you can create request in php(.net use webrequest, java equivalent to webclient) using fopen to any URL and get content from outside your domain and parse the output you want.

following the following source code to how you can use php to make request to other website without any error.

function getcontent($url)
    $cont = "";
    $fp = fopen($url,"r");
    if (!$fp)
        return "Unknown";
        $com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
        fputs($fp, $com);
        while (!feof($fp))
            $cont .= fread($fp, 2000);
        $cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
        return $cont;

$content = getcontent("");
echo $content;

hi there, I am software engineer, working in e-commerce company and passionate about all thing digital. On this blog, I share my experiments with different technology.

Tagged with: ,
Posted in html, JavaScript, PHP

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What people say about post?
seo hizmeti on Awesome wordpress ecommerce…

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 39 other followers

%d bloggers like this: