Php code reference for obtaining the current website and page content
/**
- * Get the current URL
- * Eidt by bbs.it-home.org
- */
- Function get_url (){
- $ Sys_protocal = isset ($ _ SERVER ['server _ port']) & $ _ SERVER ['server _ port'] = '000000 '? 'Https: // ': 'http ://';
- $ Php_self = $ _ SERVER ['php _ SELF ']? $ _ SERVER ['php _ SELF ']: $ _ SERVER ['script _ name'];
- $ Path_info = isset ($ _ SERVER ['path _ info'])? $ _ SERVER ['path _ info']: '';
- $ Relate_url = isset ($ _ SERVER ['request _ URI '])? $ _ SERVER ['request _ URI ']: $ php_self. (isset ($ _ SERVER ['query _ string'])? '? '. $ _ SERVER ['query _ string']: $ path_info );
- Return $ sys_protocal. (isset ($ _ SERVER ['http _ host'])? $ _ SERVER ['http _ host']: ''). $ relate_url;
- }
// Output the current URL
- $ Url = get_url ();
- Echo $ url;
- ?>
2. get the code of the page content
/**
- * Get the page content
- * Edit by bbs.it-home.org
- */
- Function get_contents ($ url ){
- If (function_exists ('File _ get_contents ')){
- $ File_contents = file_get_contents ($ url );
- } Else {
- $ Ch = curl_init ();
- $ Timeout = 5;
- Curl_setopt ($ ch, CURLOPT_URL, $ url );
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
- Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout );
- $ File_contents = curl_exec ($ ch );
- Curl_close ($ ch );
- }
// Output Content
- Return $ file_contents;
- ?>
|