Skip to content

Instantly share code, notes, and snippets.

@firedfox
Last active August 29, 2015 13:57
Show Gist options
  • Save firedfox/9362732 to your computer and use it in GitHub Desktop.
Save firedfox/9362732 to your computer and use it in GitHub Desktop.
server side code snippets for tuijian.baidu.com
<%
String HM_T_URL = "http://crs.baidu.com/s?siteId=b85f7b63582228b88367e25879c8ae89&planId=23";
String HM_T_CHARSET = "utf-8";
StringBuilder hm_t_html = new StringBuilder();
try {
String referer = java.net.URLEncoder.encode(request.getHeader("Referer"));
java.net.URL url = new java.net.URL(HM_T_URL + "&referer=" + referer);
java.net.URLConnection connection = url.openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.setUseCaches(false);
connection.addRequestProperty("X-Forwarded-For", request.getRemoteAddr());
connection.addRequestProperty("User-Agent", request.getHeader("User-Agent"));
connection.addRequestProperty("Accept-Charset", HM_T_CHARSET);
connection.addRequestProperty("Referer", request.getRequestURI());
java.io.InputStreamReader isr = new java.io.InputStreamReader(connection.getInputStream(), HM_T_CHARSET);
java.io.BufferedReader reader = new java.io.BufferedReader(isr);
String line = null;
while ((line = reader.readLine()) != null) { hm_t_html.append(line + "\n"); }
} catch (Exception e) {}
%>
<%= hm_t_html.toString() %>
<?php
$HM_T_URL = 'http://crs.baidu.com/s?siteId=b85f7b63582228b88367e25879c8ae89&planId=23';
$HM_T_CHARSET = 'utf-8';
$hm_t_ctx = @stream_context_create(array('http' => array(
'timeout' => 5,
'header' => implode("\r\n", array(
'X-Forwarded-For: ' . $_SERVER['REMOTE_ADDR'],
'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'],
'Accept-Charset: ' . $HM_T_CHARSET,
'Referer: ' . (isset($_SERVER["HTTPS"]) ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']
. (($_SERVER["SERVER_PORT"] === '80') ? '' : ':' . $_SERVER["SERVER_PORT"]) . $_SERVER["REQUEST_URI"],
)),
)));
echo @file_get_contents($HM_T_URL . '&referer=' . urlencode($_SERVER['HTTP_REFERER']), false, $hm_t_ctx);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment