Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

shell_exec Help

Hi I am have trouble getting the header info of this url. Basically the url contains some illegal characters and curl throws an error

$filesize_cmd='curl --head -g '.escapeshellarg(urldecode($direct_download_link)).' 2>&1';

curl: (3) Illegal characters found in URL

The documentation says...appending a -g parameter should fix it but still getting the error.
Note:I only get this error I pass it through shell_exec($cmd);
if I var dump the command and paste it in terminal it runs fine...

So no idea what is going wrong...:-(

btw...the url is 800 characters long...

Comments

  • Why are you using shell_exec for this instead of http://php.net/manual/en/book.curl.php ?

  • if you don't mind...I would like to use that way...could you help me out?

  • MunMun Member

    Please, please, please don't use shell_exec unless you absolutely have to.

    http://stackoverflow.com/questions/1401131/easiest-way-to-grab-filesize-of-remote-file-in-php

  • draziloxdrazilox Member
    edited October 2015

    Sounds like a bad idea, but whatever. Why are you decoding $direct_download_link ? Maybe you should rawurlencode it so all illegal characters are turned to non-illegal characters.

  • @drazilox...
    Not working using rawurencode

    @Mun
    I know....I have to use shell_exec for some other command... but using this approach it gives me a 403 error....but when using the terminal it gives me 200.I wonder why?

  • MunMun Member

    Stop investing in shell_exec, you can do this fully and safer with straight php5 and php5-curl. This my link to stackoverflow

  • noaman said: I have to use shell_exec for some other command...

    I'm curious of what that would be. I'm not sure why it doesn't work, but I'm pretty sure you're approaching this from the wrong direction.

  • @Mun...It was suppose to be easier that way ...:-(....

    I only have one query what could be the possible reasons

    shell_exec($cmd);

    gives error

    var_dump($cmd) ...copy into terminal...voila!...works like a charm.......I only need to know what is the bug that doesnot make it run in shell_exec?

  • VereloxVerelox Member
    edited October 2015

    I agree with others that it would be safer to do this through PHP, since it's already possible. Using "shell_exec" with this might be a risk especially if the URL is a variable the user can edit, as it could expose your system to injections. Here's a ready made PHP function to determine the size of a URL (the same approach used in @Mun's link):

    function getRemoteFilesize( $url ) {
        $head = array_change_key_case(get_headers(urldecode($url), TRUE));
        $size = $head['content-length'];
        return $size;
    }
    

    Example usage:

    echo getRemoteFilesize("http://example.com/index.html"); //1270 (in bytes)
    

    Edit: if you insist on using shell_exec, you might want to debug the issue by manually executing the command passed to shell_exec on the server to see where the problem lies. To do this, output the $filesize_cmd variable then copy and paste it into your SSH session to see what exactly happens:

    var_dump($filesize_cmd); //Copy the output and paste it into your SSH session.
    
  • okay...actually its a simple youtube caching and a streaming link Since youtube is banned in my country .That I plan to use for my personal usage I dont mind shell_exec ....Your getRemoteFilesize apparently doesnot work with the youtube url. I used youtube-dl webui sort of similar script that I found on github.But it downloads the file it your server.I was looking to make a script that insteads of downloading , It should cache 2-4mbs of data form youtube link and then echos it out....and do it again and again...


  • curl --head "https://r3---sn-a5m7ln7z.googlevideo.com/videoplaybac
    k?pl=44&ipbits=0&upn=Ou1BaNtoN_w&requiressl=yes&sver=3&ratebypass=yes&itag=18&dur=415.613&lmt=1442234822929462&fexp=9408710,9409069,9412843,9412913,9414764,9415365,9415485,9415869,9416023,9416075,9416126,9416556,9417260,9417707,9418153,9418448,9418908,9419309,9419446,9420348,9420983,9421013,9421295,9421709,9421742&expire=1444088755&sparams=dur,id,initcwndbps,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,pl,ratebypass,requiressl,source,upn,expire&mime=video/mp4&key=yt6&initcwndbps=25320000&id=o-AHBTr1yKaUJSV_mBYvpCJsMlh9BLsAg1cHnqMiPGKSTL&source=youtube&mm=31&mn=sn-a5m7ln7z&ms=au&mt=1444067096&mv=m&ip=*****&signature=0BAFDC7878465631B612AF3356383A52DFA8A22F.97C32EE00C52CB573D5F6B3B76C3761FB2202521"


    HTTP/1.1 200 OK
    Last-Modified: Mon, 14 Sep 2015 12:47:02 GMT
    Content-Type: video/mp4
    Date: Mon, 05 Oct 2015 17:47:38 GMT
    Expires: Mon, 05 Oct 2015 17:47:38 GMT
    Cache-Control: private, max-age=21197
    Accept-Ranges: bytes
    Content-Length: 32700109
    Connection: close
    Alternate-Protocol: 443:quic,p=0.45

  • Note ...Ip removed from the url...

  • I get 403 when I try to curl that.

  • @drazilox said:
    I get 403 when I try to curl that.

    @noaman said:
    Note ...Ip removed from the url...

  • @drazilox

    Thesed urls are ip restricted...you will always be getting a 403

  • noaman said: Thesed urls are ip restricted...you will always be getting a 403

    Also, since you removed the IP, the signature will be different.

  • okay...I got it working using a hack...but still don't understand why it was not working?

Sign In or Register to comment.