help blocking certain links

Discussion in 'PHP' started by jpinheiro, Aug 10, 2008.

  1. #1
    Ok i have a tinyurl service:

    http://dd1.us/

    but i want to block links from

    Rapidshare.com
    Rapidshare.de
    megaupload.com

    Here are all the files that would be necessary to be edited to do this:

    Index.html
    
    
    <img src="http://dd1.us/img/logo1.png"><br>
    <h1>Free Short Url Redirection</h1>
    <div class="spacer"><span></span></div>
          <form method="post" action="create.php">
    <p>
              <label title="Enter Long Url Here | http:// To Make It Work">
                <input type="text" name="url" size="40" value="http://"  /></label><br />
              <label title="Submit URL To Make A Tinyurl">
    <input type="submit" name="send" value="Make It Short!" class="submit" /></label></p>
    <div class="spacer"><span></span></div>
          </form>
    
    
    Code (markup):
    .htaccess
    
    RewriteEngine on
    RewriteRule ^([0-9]+)/?$ /go.php?id=$1 [L] 
    
    
    Code (markup):
    Create.php
    
    include("config.php");
    if (strstr($_SERVER['HTTP_REFERER'], $root));
    else { header ("Location: $rooturl"); }
    
    $ip = $_SERVER['REMOTE_ADDR'];
    $url = $_POST['url'];
    
    if(preg_match('|^http(s)?://[a-z0-9-]+(\.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url))
    {
    
    $query = "INSERT INTO $table (ip,url) VALUES ('$ip','$url')" or die('MySQL error: '.mysql_error());
    mysql_query($query);
    $qs = mysql_insert_id();
    $link = $destination . $qs;
    require 'create_template.php';
    
    } else {
    echo 'Your URL is invalid';
    
    }
    ?>
    
    
    PHP:
    Create_template.php
    
    <?
    echo "<center>Your New Short URL: <a href=$rooturl" . $qs . " target=_blank>$rooturl" . $qs . "</a></center><br />";
    ?>
    <div id="content">
    
    
    PHP:
    go.php
    
    ob_start();
    include("config.php"); 
     
     
    ?>
    		<?
    		$id = $_GET['id'];
    		if($id){
    
    			$qs = mysql_query("SELECT url FROM $table WHERE id = $id") or die('MySQL error: '.mysql_error());
        mysql_query("UPDATE url SET count=(count + 1) WHERE id = $id");
    			while($data = mysql_fetch_array($qs)){
    if ($frame == 1) {
    echo include("frame.php");
    echo "<iframe name=\"pagetext\" height=\"100%\" frameborder=\"no\" width=\"100%\" src=\"$data[0]\"></iframe>"; }
    
    else if ($frame == 0) {
    echo header("Location: $data[0]"); }
    
    
    }
    
    		}else{
    		?>
    <?}
    
    ob_flush();
    ?>
    
    
    PHP:
    These Are The Major Files IF there is way to block certain urls please let me know
     
    jpinheiro, Aug 10, 2008 IP
  2. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #2
    any1 able to figure this out? ive searched and searched
     
    jpinheiro, Aug 10, 2008 IP
  3. Dreads

    Dreads Well-Known Member

    Messages:
    1,884
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    150
    #3
    trim out megaupload.com
    in the string and rapidshare.de

    I am sure that might work
     
    Dreads, Aug 10, 2008 IP
  4. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #4
    not sure how to do that and dont know which file i would have to do it to
     
    jpinheiro, Aug 10, 2008 IP
  5. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #5
    can any1 help? no1 noes how to do this? i have supplied all files in the first post
     
    jpinheiro, Aug 10, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    
    $parts = pars_url($url);
    $host = strtolower($parts['host']);
    $host = preg_replace('~^www\.~', null, $host);
    
    $blocked = array('rapidshare.com', 'rapidshare.de', 'megaupload.com');
    
    if (in_array($host, $blocked))
    {
        // Blocked
    }
    else
    {
        // Ok
    }
    
    PHP:
     
    nico_swd, Aug 11, 2008 IP
  7. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #7
    where do i put that code

    also can a message pop up saying "This URL has been blocked"
     
    jpinheiro, Aug 11, 2008 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    Give it a go and show me what you've tried.
     
    nico_swd, Aug 11, 2008 IP
  9. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #9
    i tried in create & the index & create_template but i get errors for each one
     
    jpinheiro, Aug 11, 2008 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #10
    ^^^^^^



    And if you get errors, you gotta come a bit more specific than that. How am I supposed to help if you tell me "I get errors"?
     
    nico_swd, Aug 11, 2008 IP
  11. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #11
    In Create_Template.php --- The error is:

    Fatal error: Call to undefined function pars_url() in /home/duffy0/public_html/dd1.us/create_template.php on line 38

    Line 38 is: $parts = pars_url($url);

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

    In Create.php -- The error is:

    Fatal error: Call to undefined function pars_url() in /home/duffy0/public_html/dd1.us/create.php on line 27

    Line 27: $parts = pars_url($url);

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

    In Index.php -- The Error is:

    Fatal error: Call to undefined function pars_url() in /home/duffy0/public_html/dd1.us/index.php on line 28

    Line 28: $parts = pars_url($url);
     
    jpinheiro, Aug 11, 2008 IP
  12. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #12
    My bad, it's a typo in my code. It should read parse_url().
     
    nico_swd, Aug 11, 2008 IP
  13. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #13
    ok i added it to create.php but it just ignores it acts like it is not even there no errors just runs hte regular script normal
     
    jpinheiro, Aug 11, 2008 IP
  14. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #14
    Not sure how often I have to quote myself, lol:

     
    nico_swd, Aug 11, 2008 IP