note 104746 deleted from function.file-get-contents by salathe

From: Date: Mon, 21 Sep 2020 14:38:16 +0000
Subject: note 104746 deleted from function.file-get-contents by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215236@lists.php.net to get a copy of this message
Note Submitter: fibrefox at dynamicfiles dot de ---- If you want to insert tracking-scripts into your shopping-system, some scripts doesn't support intelligent detection of HTTPS, so i made a script i put on the server that rewrites 'http' to 'https' in the script, assuming everything has to be UTF-8 encoded (as a fallback it makes a redirect). It is important that the HTTPS-source DOES exist! <?php function file_get_contents_utf8($fn) { $opts = array( 'http' => array( 'method'=>"GET", 'header'=>"Content-Type: text/html; charset=utf-8" ) ); $context = stream_context_create($opts); $result = @file_get_contents($fn,false,$context); return $result; } header("Content-Type: text/html; charset=utf-8"); $tPath = "URL YOU WANT TO MODIFY"; $result = file_get_contents_utf8("http://".$tPath); if( $result == false){ header("Location: https://".$tPath); // fallback exit(); } else{ echo mb_ereg_replace("http","https",$result); } ?>

« previous php.notes (#215236) next »