Jump to content

my page works in php5 but not in php4


superaktieboy

Recommended Posts

Hey guys

 

i have just recently created this function to get a video from youtube, it uses the function readfile() to use it also when the website is block and 'remotefsize()' to get the remote file size (custom function)

the file can also read two images from youtube (also using readfile) depending an the get variables it gets which is 'http://img.youtube.com/vi/youtubeID/default.jpg' amd 'http://img.youtube.com/vi/youtubeID/0.jpg' (where youtubeID is the id that leads to the youtube video)

in the function remotefsize() it used get_headers() which wasn't available in php4, so i got some kind of 'emulator' for it from php.net

so i got that all working, so now the file it self works perfect in both php4 and php5 (as in they both download normal files when going directly to that page), but when i use as an flash argument to play it, it works only in php5 but not in php4..

what am i doing wrong here?

this is the file itself:

<?php

/*****
*  This function is created by "denilson at vialink dot com dot br" from php.net
*  and was found in the comments for the function 'get_headers'
*  Please note: a few minor changes have been made in this function!
*******/
if(!function_exists('get_headers')) {
    function get_headers($url, $format=0) {
        $url=parse_url($url);
        $end = "\r\n\r\n";
        $fp = fsockopen($url['host'], (empty($url['port']) ? 80 : $url['port']), $errno, $errstr, 30);
        if ($fp) {
            $out  = "GET / HTTP/1.1\r\n";
            $out .= "Host: ".$url['host']."\r\n";
            $out .= "Connection: Close\r\n\r\n";
            $var  = '';
            fwrite($fp, $out);
            while (!feof($fp)) {
                $var .= fgets($fp, 1280);
                if(strpos($var,$end)) {
				break;
			}
            }
            fclose($fp);

            $var=preg_replace("/\r\n\r\n.*\$/",'',$var);
            $var=explode("\r\n",$var);
            if($format) {
                foreach($var as $i) {
                    if(preg_match('/^([a-zA-Z -]+): +(.*)$/',$i,$parts)) {
                        $v[$parts[1]] = $parts[2];
                    }
                }
                return $v;
            } else {
            return $var;
            }
        }
    }
}

if(isset($_GET['vid']) && isset($_GET['did'])) {
$vid = $_GET['vid'];
$did = $_GET['did'];
} else if (isset($_GET['vid']) && ((isset($_GET['get_image_only']) && $_GET['get_image_only'] == 'true') || (isset($_GET['get_big_image']) && $_GET['get_big_image'] == 'true')))  {
$vid = $_GET['vid'];
} else {
die('We are missing something, you got 3 guesses!');
}
function remotefsize($url) {
$sch = parse_url($url);
if (($sch['scheme'] != "http") && ($sch['scheme'] != "https")) {
	return false;
}
$headers = get_headers($url, 1);
if ((!array_key_exists("Content-Length", $headers))) {
	return false;
}
return $headers["Content-Length"];
}

$yt_url = "http://youtube.com/get_video?video_id=$vid&t=$did";
$content_type = "video/flv";
if(isset($_GET['get_image_only']) && $_GET['get_image_only'] == 'true') {
$yt_url = "http://img.youtube.com/vi/$vid/default.jpg";
$content_type = "image/jpeg";
} else if (isset($_GET['get_big_image']) && $_GET['get_big_image'] == 'true') {
$yt_url = "http://img.youtube.com/vi/$vid/0.jpg";
$content_type = "image/jpeg";
}

$yt_size = remotefsize($yt_url);
header ("Content-transfer-encoding: binary");
header ("Content-Type: ".$content_type);
header ("Content-Disposition: attachment; filename=\"" . basename($yt_url) . "\"");
header ("Content-Length: " . $yt_size);
header ("Pragma: public");
header ("Expires: 0");
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header ("Cache-Control: private");
readfile($yt_url);

?>

 

thanks

Link to comment
Share on other sites

sorry how do you mean? if you mean i how call the flash its like this:

<?php
$get_array = YoutubeGetLink('IbrjM4aAWHY'); // YoutubeGetLink() generates a link liket his: get.php?vid=IbrjM4aAWHY&did=OEgsToPDskJ1K9lLbCNe_wgYgqZOPhzG&filetype=.flv
$link = $get_array['link'];
?>
<div id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>
<script type="text/javascript">
<!--
var object = new SWFObject("argh_player.swf", "mediaplayer", "425", "350", "7");
object.addParam("allowfullscreen", "true");
object.addVariable("width", "425");
object.addVariable("height", "351");
object.addVariable("showstop", "true");
object.addVariable("file", encodeURIComponent("<?php echo $link; ?>"));
object.addVariable("image", encodeURIComponent("<?php echo $img; ?>"));
object.addVariable("type", "flv"); // this forces to read the file as an .flv file
object.write("container");
-->
</script>

Link to comment
Share on other sites

truthly your codes looks all ok to me.............

 

you sure the settings in php4 are all the same as php5............

 

see it all about settings using the header so much mate..............

 

also i noticed your using javascript shame as your idear might earn you money in all php..

 

 

Link to comment
Share on other sites

yh thats what i thought about the code being ok :S but erm about the settings in php, i am not sure coz i use xampp, and switch using the php switcher, but i haven't changed anything at all in the php.ini for both php4 and php5..

and what do you mean with "see it all about settings using the header so much mate"

and last.. so you mean calling the code without javascript, just plain HTML.. btw the flash player is not mine, its JW Flash Player..

so you mean something like this (copied straight from FireBug after fully loaded):

<embed id="mediaplayer" width="425" height="350" flashvars="width=425&height=351&showstop=true&file=get.php%3Fvid%3DW2SCxlqR8RU%26did%3DOEgsToPDskIPmpYbK8F3VuFP2Q-zQQiO%26filetype%3D.flv&image=get.php%3Fvid%3DW2SCxlqR8RU%26get_image_only%3Dtrue%26file_type%3D.jpg&type=flv" allowfullscreen="true" quality="high" name="mediaplayer" style="" src="argh_player.swf" type="application/x-shockwave-flash"/>

 

 

greeetzz

Link to comment
Share on other sites

nope nothing, but i think i have found the problem.. when downloading the video directly, in php5 the browser knows the filesize, but in php4 it doesn't.. infat it goes even past the actual filesize!

screenshot, the properties window is downloaded using php5, the download window is downloaded using php4:

untitled536cc.jpg

Link to comment
Share on other sites

i fixed it..

it was some bug in remotefsize(), which i rewrote without the use of get_headers()

this is the new function, works in both php4 & php5:

<?php
function remotefsize($url) {
$path = parse_url($url);
$fso = @fsockopen($path['host'], 80);
if ($fso) {
	$header = 'GET ' . $url . ' HTTP/1.0' . "\n";
	$header .= 'Host: ' . $path['host'] . "\n\n";
	fwrite($fso, $header);

	$buffer = '';
	while ($tmp = fread($fso, 1024)) {
		$buffer .= $tmp;
	}

	$matches = Array();
	preg_match('/Content-Length: ([0-9]+)/', $buffer, $matches);

	return substr($buffer, @$matches[1]);
} else {
	return false;
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.