fopen_error = $string;') ); $fp = fopen( $url, 'r'); if( $fp !== false ) { $buffer = min( $maxlen, 4096 ); while ( !feof( $fp ) && !( strlen( $content ) >= $maxlen ) ) { $content .= fread( $fp, $buffer ); } fclose( $fp ); } if( $initial_timeout !== false ) @ini_set( 'default_socket_timeout', $initial_timeout ); if( $initial_user_agent !== false ) @ini_set( 'user_agent', $initial_user_agent ); restore_error_handler(); if( !$content ) { //global $ydb; //$content = 'Error: '.strip_tags( $ydb->fopen_error ); return false; } return $content; } // Get remote content using fsockopen. Needs sanitized $url. Returns $content or false function yourls_get_remote_content_fsockopen( $url, $maxlen = 4096, $timeout = 5 ) { // get the host name and url path $parsed_url = parse_url( $url ); $host = $parsed_url['host']; if ( isset( $parsed_url['path'] ) ) { $path = $parsed_url['path']; } else { $path = '/'; // the url is pointing to the host like http://www.mysite.com } if ( isset( $parsed_url['query'] ) ) { $path .= '?' . $parsed_url['query']; } if ( isset( $parsed_url['port'] ) ) { $port = $parsed_url['port']; } else { $port = '80'; } $response = false; // connect to the remote server $fp = @fsockopen( $host, $port, $errno, $errstr, $timeout ); var_dump( $errno, $errstr ); if( $fp !== false ) { // send some fake headers to mimick a standard browser fputs($fp, "GET $path HTTP/1.0\r\n" . "Host: $host\r\n" . "User-Agent: " . yourls_http_user_agent() . "\r\n" . "Accept: */*\r\n" . "Accept-Language: en-us,en;q=0.5\r\n" . "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" . "Keep-Alive: 300\r\n" . "Connection: keep-alive\r\n" . "Referer: http://$host\r\n\r\n"); // retrieve the response from the remote server $buffer = min( $maxlen, 4096 ); while ( !feof( $fp ) && !( strlen( $response ) >= $maxlen ) ) { // get more or less $maxlen bytes (between $maxlen and ($maxlen + ($maxlen-1)) actually) $response .= fread( $fp, $buffer ); } fclose( $fp ); } else { //$response = trim( "Error: #$errno. $errstr" ); return false; } // return the file content return $response; } // Return funky user agent string function yourls_http_user_agent() { return yourls_apply_filter( 'http_user_agent', 'YOURLS v'.YOURLS_VERSION.' +http://yourls.org/ (running on '.YOURLS_SITE.')' ); }