Announcement

Collapse
No announcement yet.

php help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • php help

    Hi,

    I'm having trouble with this anti leech script.

    What I want is for it to accept to domains.....

    Both http://www.localhost.com and http://localhost.com because otherwise it thinks anyone coming from http://localhost.com is a leecher.

    Any ideas how I can work this ?

    Thanks !



    PHP Code:
    $domain="www.localhost.com";

    ////////////////////////////////////////

    $folder="/path to files/";
    $filename=stripslashes(urldecode($QUERY_STRING));
    $refr=getenv("HTTP_REFERER");
    list(
    $remove,$stuff)=split('//',$refr,2);
    list(
    $home,$stuff)=split('/',$stuff,2);
    //can be replaced with
    if ($home!=$domain){readfile("http://www.localhost.com/index.php");exit;
    //if($home!=$domain){die("<h1>Leecher!</h1>This file is from $domain");
    }else{
    $fp[email protected]fopen("http://".$domain."/".$folder."/".$filename,"r");
    if(
    $fp){
    if (
    ereg(".zip",$filename)){$xtype="application/x-zip-compressed";}
    elseif(
    ereg(".exe",$filename)){$xtype="application/x-msdownload";}
    elseif(
    ereg(".hpx",$filename)){$xtype="application/mac-binhex40";}
    else{
    $xtype="application/octet-stream";}
    Header("Content-Type: $xtype");
    Header("Accept-Ranges: bytes");
    Header("Content-Disposition: ; Filename=$filename");
    readfile("http://".$domain."/".$folder."/".$filename);
    }else{
    //can be replaced with
    //readfile("http://www.localhost.com/error404.html");exit;
    die("file not found");
    }} 

  • #2
    you could just use 2 instances of the script, one for each case
    NXSupport Admin

    Comment


    • #3
      Surely that is overkill at the very least if all I want in that script is a statement saying $domain OR $domain2

      I'm just not sure what the syntax is to do that in php.....

      Comment


      • #4
        Maybe if someone could tell me the syntax for an OR or AND statement I might be able to work this out myself.................

        Thanks

        Comment


        • #5
          well evidently using php.net is too much grief for you


          you can use AND and OR but it's better to use && and || for some reason

          Comment


          • #6
            well evidently you couldn't just help without feeling the need to be crappy

            Thankyou

            Comment


            • #7
              Try this, you can add multiple domains that are allowed.

              Coded to vB3 coding standards of course

              PHP Code:
              <?php
              $domains
              [] = 'www.localhost.com';
              $domains[] = 'localhost.com';
              $folder '/path to files/';

              ////////////////////////////////////////

              $filename stripslashes(urldecode($HTTP_SERVER_VARS['QUERY_STRING']));
              $ref parse_url($HTTP_SERVER_VARS['HTTP_REFERER']);

              //can be replaced with
              if (!in_array($ref['host'], $domains)) {
                  
              header('Location: [url]http://www.localhost.com/index.php[/url]');
                  exit;
              } else {
                
              $fp[email protected]fopen('http://' $domain '/' $folder '/' $filename'r');
                if(
              $fp) {
                      
              $extension substr(strrchr($filename'.'),1);
                      switch(
              $extension) {
                          case 
              'zip':
                            
              $xtype 'application/x-zip-compressed';
                          break;
                      
                        case 
              'exe':
                              
              $xtype 'application/x-msdownload';
                          break;
                      
                        case 
              'hpx':
                              
              $xtype 'application/mac-binhex40';
                          break;
                      
                        default:
                               
              $xtype 'application/octet-stream';
                          break;
                      }
                  
              header("Content-Type: $xtype");
                  
              header('Accept-Ranges: bytes');
                  
              header("Content-Disposition: ; Filename=$filename");
                  
              readfile('http://' $domain '/' $folder '/' $filename);
               } else {
                  die(
              "file not found");
                }
              }

              ?>
              Last edited by Scott MacVicar; Fri 23 Aug '02, 9:33am.
              Scott MacVicar

              My Blog | Twitter

              Comment


              • #8
                Thankyou PPN for trying to help !!

                I had to change the location : part to :

                PHP Code:
                if (in_array($ref['host'], $domains)) { 
                header('Location: [url=http://www.localhost.com/index.php]http://www.localhost.com/index.php[/url]'); 
                exit; 
                } else { 
                Because otherwise it dumped the <a href="............ in the location bar.

                However, it's so close to working !!

                It's having problems validating the domain because it keeps using the location route to back out as if I was a leecher which obviously I'm not

                Any ideas ?

                Thanks again for your help
                Last edited by bahbah; Mon 17 Feb '03, 6:06am.

                Comment


                • #9
                  change it to !in_array

                  i missed out the exclamation mark
                  Scott MacVicar

                  My Blog | Twitter

                  Comment


                  • #10
                    Got it working thankyou PPN !!

                    I had to change 2 things :

                    readfile('http://' . $domain . '/' . $folder . '/' . $filename);

                    $domain wasn't stated so I changed it to $domains[0]

                    The same goes for here :

                    [email protected]('http://' . $domain . '/' . $folder . '/' . $filename, 'r');


                    Man, this script had been bugging me for so long thankyou so much for you help

                    Comment

                    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                    Working...
                    X