我的部落格式使用bo-blog,h网址是
http://qoo320....t.us,我想再部落格中出售我的文字连结,但是广告网站都要我加入一段text ad code 在我的网页里面,Copy and paste this code inside your PHP code,内容是一段<?php 开头 的语法。
php好难喔。我到底要如何加入这段语法ㄋ。
复制程式
Install PHP Routine
* Copy and paste this code inside your PHP code
* Done
Important note
* This ad slot is set for site wide links, so you will need to place the code in your website so that it will appear on all pages of your website.
* Advertisers monitor the visitors that they get from text links by looking at their web analytics reports. To ensure you earn the most income, please place the ad code above the fold the layout of your website; that will allow them to receive clicks.
* When you have placed the code in your website and it has been successfully installed, you will receive an email from us and we will start selling and listing your website in our inventory. Thanks for your attention.
view plaincopy to clipboardprint?
1. <?php
2. function ask2link_ad_helper($url)
3. {
4. $content = '';
5. $done=false;
6. if (ini_get('allow_url_fopen') == '1') {
7. if ($fp = @fopen($url, 'r')) {
8. while ($line = @fread($fp, 1024)) {
9. $content .= $line;
10. $done=true;
11. }
12. }
13. }
14. if (!$done) {
15. // get the host name and url path
16. $parsedUrl = parse_url($url);
17. $host = $parsedUrl['host'];
18. if (isset($parsedUrl['path'])) {
19. $path = $parsedUrl['path'];
20. }
21.
22. $timeout = 10;
23. // connect to the remote server
24. $fp = @fsockopen($host, '80', $errno, $errstr, $timeout );
25.
26. if( !$fp ) {
27. // echo "Cannot retrieve $url";
28. } else {
29. // send the necessary headers to get the file
30. @fputs($fp, "GET $path HTTP/1.0\r\n" .
31. "Host: $host\r\n\r\n");
32.
33. // retrieve the response from the remote server
34. while ( $line = @fread( $fp, 4096 ) ) {
35. $content .= $line;
36. }
37. @fclose( $fp );
38. // strip the headers
39. $pos = strpos($content, "\r\n\r\n");
40. $content = substr($content, $pos + 4);
41. }
42. }
43.
44. // return the file content
45. return $content;
46. }
47.
48. function ask2link_ad($url) {
49. $h = urlencode($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
50. $content=ask2link_ad_helper($url."?x-h=".$h);
51. if (!preg_match('/\<Error/',$content)) {
52. echo $content;
53. }
54. }
55.
56. echo ask2link_ad('http://s3.amazonaws.com/mf1/ad/3144377774c076d5439b1246379080/ad_content');
57.
58. ?>
<?php
function ask2link_ad_helper($url)
{
$content = '';
$done=false;
if (ini_get('allow_url_fopen') == '1') {
if ($fp = @fopen($url, 'r')) {
while ($line = @fread($fp, 1024)) {
$content .= $line;
$done=true;
}
}
}
if (!$done) {
// get the host name and url path
$parsedUrl = parse_url($url);
$host = $parsedUrl['host'];
if (isset($parsedUrl['path'])) {
$path = $parsedUrl['path'];
}
$timeout = 10;
// connect to the remote server
$fp = @fsockopen($host, '80', $errno, $errstr, $timeout );
if( !$fp ) {
// echo "Cannot retrieve $url";
} else {
// send the necessary headers to get the file
@fputs($fp, "GET $path HTTP/1.0\r\n" .
"Host: $host\r\n\r\n");
// retrieve the response from the remote server
while ( $line = @fread( $fp, 4096 ) ) {
$content .= $line;
}
@fclose( $fp );
// strip the headers
$pos = strpos($content, "\r\n\r\n");
$content = substr($content, $pos + 4);
}
}
// return the file content
return $content;
}
function ask2link_ad($url) {
$h = urlencode($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$content=ask2link_ad_helper($url."?x-h=".$h);
if (!preg_match('/\<Error/',$content)) {
echo $content;
}
}
echo ask2link_ad('http://s3.amazonaws.com/mf1/ad/3144377774c076d5439b1246379080/ad_content');
?>