Hi there,
i am developing a home-made php script licesning system to locate a file but when i have created the file in the directory on my webserver and not sure why i get this error when i created the license checking already
function checkLicense($site,$serv)
{
$r = curl_init($serv.urlencode($site));
curl_setopt($r,CURLOPT_HEADER,false);
curl_setopt($r,CURLOPT_RETURNTRANSFER,true);
$o=(int)trim(curl_exec($r));
curl_close($r);
return (bool)$o;
}
$site="".$_SERVER['HTTP_HOST'].".lic";
$serv = 'http://www.willbc.com/licenses/bccms/';
if(checkLicense($site,$serv))
{
echo "You have a valid license to use this software, enjoy.";
}
else
{
echo "Sorry, afraid you do not have a valid license.
<br/> This application is disabled until a license has been granted for this site.<br/>
To get a lincense please head on over here:<br/>
<a>Purchase a license for $site</a><br/>
<br/>If this is not a pay to get script:<br/>
<a>Acquire a license for".$site."</a>";
}
Now when i test the script i get the sorry afraid you do not have a valid license error even when i create the .lic file on my server in the directories above
How can i fix this?
The response from curl_exec when CURLOPT_RETURNTRANSFER is true is the content of the webpage. Casting that string to an integer results in 0, then you cast that to a boolean which is false, so you return false. You also probably need some kind of a 404 error check.
so how can i place an error check in there? to get it fixed?
[fphp]curl_getinfo/fphp will give the information you need, more specifically, look at CURLINFO_HTTP_CODE.

are you saying i’d need to replace returntransfer with CURLINFO_HTTP_CODE?
Is this correct??
Checking for a license this way is flawed in my opinion, but we won’t get into that as I’m pretty sure we had this debate in an earlier thread.
This is untested, but the logic is there. I’m pretty sure you don’t need HEADER option either, but it should get you going…
<?php
function check_site_licence($licence_server, $site){
$curl = curl_init(
sprintf(
'%s/%s.lic',
$licence_server,
urlencode($site)
)
);
curl_setopt_array(
$curl,
array(
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true
)
);
curl_exec($curl);
return 200 === curl_getinfo($curl, CURLINFO_HTTP_CODE) ? true : false ;
}
if(true === check_site_licence('http://www.willbc.com/licenses/bccms', 'google.com')){
#valid
}else{
#invalid
}
?>
thanks it works how do i remove this so this doesnt get displayed when i get a valid or invalid license?
HTTP/1.1 404 Not Found Date: Thu, 28 Jan 2010 09:37:52 GMT Server: Apache Content-Type: text/html; charset=iso-8859-1
function check_site_licence($licence_server, $site){
$curl = curl_init(
sprintf(
'%s/%s.lic',
$licence_server,
urlencode($site)
)
);
curl_setopt_array(
$curl,
array(
CURLOPT_NOBODY => true,
CURLOPT_RETURNTRANSFER => true
)
);
curl_exec($curl);
return 200 === curl_getinfo($curl, CURLINFO_HTTP_CODE) ? true : false ;
}