Reputation: 1
<?php
$url='http://www.cfp.net/find/EnhancedSearch.aspx';
$s = @file_get_contents($url);
if (empty($s))
{
// Web page empty/access failure
echo "sorry!";
}
else
{
echo($s);
}
?>
------i tried with htmlextension page it works and also work for "http://www.cfp.net" but it shows error message as sorry that means $s is empty why $s is not getting any content in above code.
Please help me get content of http://www.cfp.net/find/EnhancedSearch.aspx in variable $s and save the content in html page i.e with extension html using pure php code.
Upvotes: 0
Views: 601
Reputation: 23244
Your problem is to do with not overriding the default user agent for the request.
The server is rejecting PHPs default user agent.
For some reason it accepts a wget request but not a PHP request by default - strange.
If you change it to a spoofed browser user agent then the request works.
Heres the full code:
$opts = array(
'http'=>array(
'method'=>"GET",
'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6',
)
);
$context = stream_context_create($opts);
$url='http://www.cfp.net/find/EnhancedSearch.aspx';
$s = file_get_contents($url,false,$context);
if (empty($s))
{
// Web page empty/access failure
echo "sorry!";
}
else
{
echo($s);
}
Upvotes: 3
Reputation: 6155
I'd advice you to check out this on the server..
[NullReferenceException: Object reference not set to an instance of an object.]
CertificantSearch.CFP.get_bMobile() in D:\2.0Projects\CFPBoard\Certificant\CertificantSearch\CFP.Master.cs:23
CertificantSearch.EnhancedSearch.Page_Load(Object sender, EventArgs e) in D:\2.0Projects\CFPBoard\Certificant\CertificantSearch\EnhancedSearch.aspx.cs:151
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Since this gives internal error and since you suppress errors on top, it even can't report any errors. And I'd advice using CURL
Upvotes: 0