note 104746 modified in function.file-get-contents by danbrown

From: Date: Tue, 05 Jul 2011 13:37:46 +0000
Subject: note 104746 modified in function.file-get-contents by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181237@lists.php.net to get a copy of this message
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); } ?> --was-- 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); } http://php.net/manual/en/function.file-get-contents.php

« previous php.notes (#181237) next »