3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Instagram's proxy API * reads Instagram pages and gets embedded data, * then returns it as json or jsonp. * By Francisco Diaz :: picssel.com * Revision March 2015 */ /*$sawOrigin = false; $originHeader = $_SERVER['HTTP_ORIGIN']; $originHeader = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : null; if ($originHeader) { echo "Origin header value: $originHeader"; }*/ /***** get request origin and set domain restrictions *****/ $HTTP_ORIGIN = $_SERVER['HTTP_ORIGIN']; // 1). ALL domains // header("Access-Control-Allow-Origin: *"); // 2). Single domain /* if ($HTTP_ORIGIN == "http://www.picssel.com"){ header("Access-Control-Allow-Origin: $HTTP_ORIGIN"); } */ // 3). Several domains, e.g. http://picssel.com, http://fiddle.jshell.net, etc. $domains_allowed = array("http://www.picssel.com", "http://www.picssel.ca"); if(in_array( $HTTP_ORIGIN, $domains_allowed )){ header("Access-Control-Allow-Origin: $HTTP_ORIGIN"); } /***** functions *****/ // sanitize input function sanitize_input($input){ $input = trim($input); $input = stripslashes($input); $input = strip_tags($input); $input = htmlspecialchars($input); return $input; }; // process data function process_data($dataFile, $requestType){ $data_length = strlen($dataFile); if( $data_length > 0 ){ $start_position = strpos( $dataFile ,'{"static_root"' ); // start position $trimmed_before = trim( substr($dataFile, $start_position) ); // trim preceding content $end_position = strpos( $trimmed_before, '</script>'); // end position $trimmed = trim( substr( $trimmed_before, 0, $end_position) ); // trim content $jsondata = substr( $trimmed, 0, -1); // remove extra trailing ";" header("HTTP/1.0 200 OK"); // JSONP response if(array_key_exists('callback', $_GET)){ header('Content-Type: text/javascript; charset=utf8'); $callback = $_GET['callback']; return $callback."(".$jsondata.");"; } // JSON response else { header('Content-Type: application/json; charset=utf-8'); return $jsondata; } } else { // invalid username or media header("HTTP/1.0 400 BAD REQUEST"); header('Content-Type: text/html; charset=utf-8'); die("invalid $requestType"); } }; /***** Get user's input *****/ $user = sanitize_input( $_GET['user'] ); // expects something like "instagram" (username) $media = sanitize_input( $_GET['media'] ); // expects something like "mOFsFhAp4f" (shortcode) /***** set context *****/ $context = stream_context_create(array( 'http' => array( 'timeout' => 10 // in seconds ) ) ); /***** validate request type and return response *****/ // user, including last 20 media posts if( !empty($user) && empty($media) ){ $requestType = "user"; $dataFile = @ file_get_contents("http://instagram.com/".$user, NULL, $context); echo process_data($dataFile, $requestType); } // media elseif( empty($user) && !empty($media) ){ $requestType = "media"; $dataFile = @ file_get_contents("http://instagram.com/p/".$media, NULL, $context); echo process_data($dataFile, $requestType); } // invalid : two or more parameters were passed elseif( !empty($user) && !empty($media) ){ header("HTTP/1.0 400 BAD REQUEST"); header('Content-Type: text/html; charset=utf-8'); die("only one parameter allowed"); } // invalid : none or invalid parameters were passed elseif( empty($user) && empty($media) ){ header("HTTP/1.0 400 BAD REQUEST"); header('Content-Type: text/html; charset=utf-8'); die("invalid parameters"); }; ?>
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key "HTTP_ORIGIN" in /in/oq58j on line 18 Warning: Undefined array key "user" in /in/oq58j on line 72 Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/oq58j on line 36 Warning: Undefined array key "media" in /in/oq58j on line 73 Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/oq58j on line 36 Warning: Cannot modify header information - headers already sent by (output started at /in/oq58j:18) in /in/oq58j on line 104 Warning: Cannot modify header information - headers already sent by (output started at /in/oq58j:18) in /in/oq58j on line 105 invalid parameters
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key "HTTP_ORIGIN" in /in/oq58j on line 18 Warning: Undefined array key "user" in /in/oq58j on line 72 Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/oq58j on line 36 Warning: Undefined array key "media" in /in/oq58j on line 73 Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/oq58j on line 36 Warning: Cannot modify header information - headers already sent by (output started at /in/oq58j:18) in /in/oq58j on line 104 Warning: Cannot modify header information - headers already sent by (output started at /in/oq58j:18) in /in/oq58j on line 105 invalid parameters
Output for 8.0.0 - 8.0.30
Warning: Undefined array key "HTTP_ORIGIN" in /in/oq58j on line 18 Warning: Undefined array key "user" in /in/oq58j on line 72 Warning: Undefined array key "media" in /in/oq58j on line 73 Warning: Cannot modify header information - headers already sent by (output started at /in/oq58j:18) in /in/oq58j on line 104 Warning: Cannot modify header information - headers already sent by (output started at /in/oq58j:18) in /in/oq58j on line 105 invalid parameters
Output for 5.4.0, 7.2.1, 7.3.24 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined index: HTTP_ORIGIN in /in/oq58j on line 18 Notice: Undefined index: user in /in/oq58j on line 72 Notice: Undefined index: media in /in/oq58j on line 73 Warning: Cannot modify header information - headers already sent by (output started at /in/oq58j:18) in /in/oq58j on line 104 Warning: Cannot modify header information - headers already sent by (output started at /in/oq58j:18) in /in/oq58j on line 105 invalid parameters
Output for 7.3.32 - 7.3.33
invalid parameters

preferences:
137.88 ms | 401 KiB | 121 Q