OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
php-general Digest 3 Feb 2008 13:26:16 -0000 Issue 5272

php-general-digest-helplists.php.net
Date: Sun Feb 03 2008 - 07:26:16 CST


php-general Digest 3 Feb 2008 13:26:16 -0000 Issue 5272

Topics (messages 268578 through 268589):

Re: Server to client file transfer with authorization: file always corrupt
        268578 by: Nathan Rixham

Re: how can make like http://wallpaper.pc86.com ?
        268579 by: Jonesy

Re: PEAR website and MSIE 6
        268580 by: Jochem Maas

" using the mail() command
        268581 by: Ron Piggott
        268582 by: Ron Piggott

how to make multiple website on one host
        268583 by: jeffry s
        268584 by: Larry Garfield
        268585 by: Jim Lucas

flash with PHP
        268586 by: Alain Roger

php competion
        268587 by: doc

Re: Jacco van Hooren
        268588 by: Jim Lucas

PHP5 and XSLTProcessor: disable validation
        268589 by: Siegfried Gipp

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


szalinski wrote:
> Hi
>
> I am having trouble with a file transfer script, as you can see, I am
> trying trying to keep the code as simple as possible.
>
> But everytime I download a file with it, it is corrupt. For example, when
> I download a small .rar file, just to test, it is always corrupt
> ('Unexpected end of archive'). I also cleared my browser cache just to be
> sure, but same problem.
>
> I just can't get my head around why it wouldn't be working as it is...
>
> A couple of questions:
>
> Have I got too many header requests?
> Do I need to worry about output buffering, which is possibly corrupting
> the file output (if so, please tell me what to do!)?
> Is there an easier way to get returned response header and get a
> redirected link, instead of finding and cutting strings?
> Is there maybe something wrong with the structure or order of the header
> requests, and/or returned headers etc?
>
> Here is what I have so far:
>
> <?php
>
> //ob_start();
> //ob_end_flush();
> //ob_implicit_flush(TRUE);
>
> $rslogin = '';
> $rspass = '';
> $link = addslashes(trim($_POST['link']));
>
> function cut_str($str, $left, $right)
> {
> $str = substr(stristr($str, $left), strlen($left));
> $leftLen = strlen(stristr($str, $right));
> $leftLen = $leftLen ? -($leftLen) : strlen($str);
> $str = substr($str, 0, $leftLen);
> return $str;
> }
>
> // Get the full premium link, and store it in $full_link after the
> redirect. *Surely* there is an easier way to get redirections?
>
> if(strlen($link)>0)
> {
> $url = parse_url($link);
> $fp = fsockopen($url['host'], 80, $errno, $errstr);
> if (!$fp)
> {
> $errormsg = "Error: <b>$errstr</b>, please try again later.";
> echo $errormsg;
> exit;
> }
>
> $vars = "dl.start=PREMIUM&uri={$url['path']}&directstart=1";
> $out = "POST {$url['path']} HTTP/1.1\r\n";
> $out .= "Host: {$url['host']}\r\n";
> $out .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows
> NT 5.1)\r\n";
> $out .= "Authorization: Basic
> ".base64_encode("{$rslogin}:{$rspass}")."\r\n";
> $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
> $out .= "Content-Length: ".strlen($vars)."\r\n";
> $out .= "Connection: Close\r\n\r\n";
> fwrite($fp, $out);
> fwrite($fp, $out.$vars);
> while (!feof($fp))
> {
> $string .= fgets($fp, 256);
> }
> //Tell us what data is returned
> //print($string);
> fclose($fp);
>
> if (stristr($string, "Location:"))
> {
> $redirect = trim(cut_str($string, "Location:", "\n"));
> $full_link = addslashes(trim($redirect));
> }
>
> //print($string);
> //print("<html><body><h1>".$full_link."</h1>");
>
>
>
> if ($full_link)
>
> {
>
> // Get info about the file we want to download:
>
> $furl = parse_url($full_link);
> $fvars = "dl.start=PREMIUM&uri={$furl['path']}&directstart=1";
> $head = "Host: {$furl['host']}\r\n";
> $head .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT
> 5.1)\r\n";
> $head .= "Authorization: Basic
> ".base64_encode("{$rslogin}:{$rspass}")."\r\n";
> $head .= "Content-Type: application/x-www-form-urlencoded\r\n";
> $head .= "Content-Length: ".strlen($fvars)."\r\n";
> $head .= "Connection: close\r\n\r\n";
> $fp = fsockopen($furl['host'], 80, $errno, $errstr);
> if (!$fp)
> {
> echo "The script says <b>$errstr</b>, please try again later.";
> exit;
> }
> fwrite($fp, "POST {$furl['path']} HTTP/1.1\r\n");
> fwrite($fp, $head.$fvars);
> while (!feof($fp))
> {
> //Keep reading the info until we get the filename and size from
> the returned Header - is there no easy way
> //of doing this? I also don't like the way I have to 'find' the
> redirected link (above).??
> $tmp .= fgets($fp, 256);
> $d = explode("\r\n\r\n", $tmp);
>
> // I tried changing this to if ($d), { etc.., (instead of
> $d[1]) and the download of the rar file *wasn't* corrupt, it just had a
> filetype of x-rar-compressed instead of
> //application/octet-stream, and the filesize was 'unknown' -
> now this is just confusing me...! So i think (and guess) the problem of
> the file corruption is here,
> //because it must add some data to the filestream which
> corrupts it. Darn.
> if($d[1])
> {
> preg_match("#filename=(.+?)\n#", $tmp, $fname);
> preg_match("#Content-Length: (.+?)\n#", $tmp, $fsize);
> $h['filename'] = $fname[1] != "" ? $fname[1] :
> basename($furl['path']);
> $h['fsize'] = $fsize[1];
> break;
> }
>
> }
> fclose($fp);
>
> $filename = $h['filename'];
> $fsize = $h['fsize'];
>
> //Now automatically download the file:
>
> header("Cache-Control:");
> header("Cache-Control: public");
> header("Content-Type: application/octet-stream");
> header("Content-Disposition: attachment; filename=".$filename);
> header("Accept-Ranges: bytes");
> if(isset($_SERVER['HTTP_RANGE']))
> {
> list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);
> $range = str_replace("-", "", $range);
> $new_length = $fsize - $range;
> header("HTTP/1.1 206 Partial Content");
> header("Content-Length: $new_length");
> }
> else
> {
> header("Content-Length: ".$fsize);
> }
> $f2vars = "dl.start=PREMIUM&uri={$furl['path']}&directstart=1";
> $head2 = "Host: {$furl['host']}\r\n";
> $head2 .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows
> NT 5.1)\r\n";
> $head2 .= "Authorization: Basic
> ".base64_encode("{$rslogin}:{$rspass}")."\r\n";
> $head2 .= "Content-Type: application/x-www-form-urlencoded\r\n";
> if($range != "") $head2 .= "Range: bytes={$range}-\r\n";
> $head2 .= "Content-Length: ".strlen($fvars)."\r\n";
> $head2 .= "Connection: close\r\n\r\n";
> $fp = fsockopen($furl['host'], 80, $errno, $errstr);
> if (!$fp)
> {
> echo "<span style='color:#688000; background-color:#BBDB54;
> font-size : 10pt; text-decoration: none; font-family: Trebuchet MS;'>The
> script says <b>$errstr</b>, please try again later.</span>";
> exit;
> }
> stream_set_timeout($fp, 120);
> fwrite($fp, "POST {$furl['path']} HTTP/1.1\r\n");
> fwrite($fp, $head2.$f2vars);
> fflush($fp);
> while (!feof($fp))
> {
> $download = fread($fp, 2048);
> echo $download;
> //ob_flush(); //php.net suggestion
> }
>
> //These two buggers were here originally, but I don't even know if I am
> supposed to have them here.
> flush();
> ob_flush();
> fclose($fp);
> exit;
>
> }
>
>
> }
> else
> {
> $data = "<form method=\"post\">\n";
> $data .= "<input type=\"text\" id=\"link\"
> style=\"text-align:center\" name=\"link\" size=\"60\"
> onfocus=\"if(this.value=='Enter rapidshare.com URL
> here'){this.value=''}\">\n";
> $data .= "<br><input type=\"submit\" value=\"Download\"></form>";
> echo $data;
> }
> ?>
>
> Thanks to anyone who has already helped, I hope some genius can spot an
> obvious error, because this is just beyond me!
>
> :)

I'd be correct in assuming that you have opened up the download in a
text browser to see what you've actually recieved yes?

first thing to check... your doing a fsockopen, and posting a raw http
request, meaning your getting a raw http response back, which you're
echoing straight out, so you should expect to have full http headers and
quite possibly http chunked content, rather than a nice file..

use file_get_contents with a stream_context holding all your http
request headers instead, as an easy way around it.

or check out the http class, or use zends http class, or create a quick
chunk decoder - whichever you do, first step is to actually check the
raw content and verify it's not just a raw http response :)

Nathan

attached mail follows:


On Sun, 3 Feb 2008 04:33:57 +0800, RandMan wrote:
> how can make like http://wallpaper.pc86.com ?

Hell! Why would you want to?

        http://validator.w3.org/#validate_by_uri
        Validation Output: 26 Errors

Pretty much renders as crap in 4 different browsers here.

attached mail follows:


Shawn McKenzie schreef:
> Glad I read threads that I don't care about or I wouldn't have found out
> about Firebug! I just installed it, very cool!

it can definitely make your day less painful :-)

>
> Also, considering the price of oil/gas, I'm sorry that the 'war for oil'
> didn't work out the way we had hoped. You would have thought we would
> have learned in WWII when we started the 'war for strudel'. Have you
> seen the price of strudel? It went up during WWII and has continued to
> rise.

I'm not much a strudel fan, unfortunately I'm just as hooked on oil as the next
man ... the point I was making is that alot of the 'problems' encountered in
'cyberspace' aqre pretty lame compared to the crap going on in meatspace.

the iraqi that just watched his wife and children mowed down by 'friendly fire'
probably doesn't care too much that pear.php.net crashes IE6.

> I would call you a dumb ass, but you seem very knowledgeable in PHP and
> I may need some help in the future :-)

nuff people would agree with you on the first part, some might credit me
with the second part and here's hoping I can offer some help of the third
part happens to pass.

credit given for a smarty comment ... appreciated :-)

attached mail follows:


When I use the mail($email, $subject, $message, $headers); command I
assign the value of $message as follows:

$boundary = md5(uniqid(time()));

$message = "

--$boundary
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

blah

--$boundary
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<b>Blah</b><p>

--$boundary--
";

I would like to be able to include a " in my message body --- both the
HTML and text version --- how can I accomplish this? (I use a " to
assign the value of $subject). I have been able to get \" to work ---
but \" shows when reading the e-mail, not just the ".

Thanks for your help

Ron

attached mail follows:


Thanks for the new command and help. It worked! Ron

On Sat, 2008-02-02 at 19:46 -0500, Greg Bowser wrote:
> First off, I would use heredoc syntax so you don't need to escape the
> quotes:
>
> $message = <<<EOF
> blah blah blah
> $your $stuff
> $here
> "
> '
> \ blah blah
>
> EOF;
>
> Also, since you're using text/html as your content-type, you should
> probably be using &quot; instead of ".
>
> --Greg

attached mail follows:


i am wondering whether this can be done. i know it can.
is it possible to make one website with the ability to host multiple
website.
it is something like website generator. eg: www.shopify.org

let say for example i have a website www.example.org.
i can point a domain name (www.example1.org) to the server where
www.example.org hosted,
and when user visit www.example1.org, it execute the same scripts as
www.example.org with
with different themes and website configuration.

anyone have the idea?

thanks

attached mail follows:


You can, in your code, check the $_SERVER super-global to see what domain name
was requested. You can then branch your code however you need to, just as
you can for any other conditional.

Have a look at the Drupal framework, which includes that exact feature.

On Sunday 03 February 2008, jeffry s wrote:
> i am wondering whether this can be done. i know it can.
> is it possible to make one website with the ability to host multiple
> website.
> it is something like website generator. eg: www.shopify.org
>
> let say for example i have a website www.example.org.
> i can point a domain name (www.example1.org) to the server where
> www.example.org hosted,
> and when user visit www.example1.org, it execute the same scripts as
> www.example.org with
> with different themes and website configuration.
>
> anyone have the idea?
>
> thanks

--
Larry Garfield AIM: LOLG42
larrygarfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson

attached mail follows:


jeffry s wrote:
> i am wondering whether this can be done. i know it can.
> is it possible to make one website with the ability to host multiple
> website.
> it is something like website generator. eg: www.shopify.org
>
> let say for example i have a website www.example.org.
> i can point a domain name (www.example1.org) to the server where
> www.example.org hosted,
> and when user visit www.example1.org, it execute the same scripts as
> www.example.org with
> with different themes and website configuration.
>
> anyone have the idea?
>
> thanks
>

Jeffry,

Yes, I built a site 7 years ago that could do this.

The primary site was like and administration/management console.

Then, in the background, there were a number of scripts that would run
the secondary website. All the secondary websites used the same source
directory. They referred to the $_SERVER['HTTP_HOST'] setting to figure
out which host name they were coming from / going to.

The site is still running today. Mind you that it needs some major
overhauling, but it is still used by about 400 domains clients.

Jim

attached mail follows:


Hi,

i would like to have a flash menu in my PHP website.
this is no problem.

My problem is how to exchange data between PHP andFlash (in both direction).
i found a lot of posts on this theme, but nothing with really works under
ActionScript 3 and PHP.

does anyone already solved such topic ?

thx.

--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

attached mail follows:


come on people try you skills at

http://www.rhwebhosting.com/comp/index.php

attached mail follows:


Nathan Rixham wrote:
> wish he'd turn that auto responder off.. *sigh* - he's now top of my
> contacts in gtalk..
>

That is his way of getting to the top of next weeks PostTrack Report
from Dan :)

Jim

attached mail follows:


Hi,
i'm currently learning php by implementing a blog system. This uses xsl for
transformation to (x)html. It is working so far, but it is slow.

As far as i can see the XSLTProcessor is doing a validation. Doing the same
transformation with xsltproc (the command line tool for libxslt) takes about
the same time. Adding the parameter --novalid to xsltproc speeds up things
dramatically.

Is there any possibility/option/parameter/whatever to stop XSLTProcessor
validation? I've found nothing in the documentation.

I hope i'm not wrong here. I'm new to php as well as to this list :)

regards
Siegfried Gipp