Jump to content

Problems, Database, and some PHP


Lamez

Recommended Posts

ok I have this bit of code (shown below), this is a snippet from my ELC, well it is not working well at all. It is suppose to take the base url of the inputted url, then check to see if it matches in the database, and if it does then it redirects the user to a error saying it has been blacklisted for this reason, but the reason all ways take the last result in the database. Why?

 

Snippet:

<?php
  //begin checking for blacklisted...
  
 	//$par = parse_url($n_url);
	//$n_url = $par['host'];//grab base url
	$n_url = addwww($n_url);//add www
        $n_url = addPro($n_url);//add http://

	$sel = mysql_query("SELECT * FROM `blacklist`");
	while($ck = mysql_fetch_array($sel)){
         $ck_url = $ck['url']; 
	 $o_url = $ck_url;

	 $ck_url = addwww($ck_url);//add www
	 $ck_url = addPro($ck_url);//add http://

	 if($n_url == ($ck_url)){
	   $_SESSION['o_url'] = $o_url;
	   header("Location: ?url=".$black);	
	  }
	  
        }//end while loop

  //end check, everything cleared...
?>

 

Entire Code:

<?php

ob_start();
session_start(); 
$connection = mysql_connect("****",
                            "****",
                            "****");
mysql_select_db("****", $connection);

$results = mysql_query("SELECT * FROM `site`")or die(mysql_error());
$row = mysql_fetch_array($results)or die(mysql_error());

$title = $row['name'];
$back_address = 'http://www.krazypicks.com';

function addPro($str){
   if($str != '' && strpos(strtolower($str), 'http://') !== 0){
    $str = 'http://'.$str;
  }
  return $str;
}
function addwww($str){
   if (substr($str,0,4) != 'www.') {
    $str = 'www.'.$str;
  }
  return $str;
}

$links = "<a href=\"http://www.krazypicks.com\">".$title."</a> or <a href=\"?\">Enter URL</a>";
$switch = "00";
$black =  "black";

$url = $_GET['url'];
$url = stripslashes($url);
$url = htmlspecialchars($url);
$n_url = $url;


if($url == ($switch)){
  echo $links;
}else if($url == ($black)){
$new_url = $_SESSION['o_url'];
  $q = mysql_query("SELECT * FROM `blacklist` WHERE `url` = '".$new_url."'")or die(mysql_error());
  $r = mysql_fetch_array($q);
  $reason = $r['level'];
  echo "<font color=\"red\"><b>WARNING:</b></font> This website has been blacklisted by KrazyPicks<br>";
  echo "<b>Reason:</b> ".$reason."<br><br>";
  echo $links;
}else if(empty($url)){
    print'Enter URL<br>
  <form id="form1" name="form1" method="get" action="?">
  <label>
  <input name="url" type="text" id="url" size="50" maxlength="100" />
  </label>
  <input type="submit" name="'.md5("go_s").'" id="'.md5("go_s").'" value="Go!" />
  </form><br>
   <a href="http://www.krazypicks.com">'.$title.'</a> :: <a href="http://www.servage.net/?coupon=cust33591">Hosted by Servage</a>';
}else{

    $url = addPro($url); //adds http://
    $churl = @fopen($url,'r');
    if (!$churl && !empty($url)){
     echo "<br><center>The URL does not exist, or the server is down.<br>".$links."</center>";
    }else{ 

  //begin checking for blacklisted...
  
 	//$par = parse_url($n_url);
	//$n_url = $par['host'];//grab base url
	$n_url = addwww($n_url);//add www
        $n_url = addPro($n_url);//add http://

	$sel = mysql_query("SELECT * FROM `blacklist`");
	while($ck = mysql_fetch_array($sel)){
         $ck_url = $ck['url']; 
	 $o_url = $ck_url;

	 $ck_url = addwww($ck_url);//add www
	 $ck_url = addPro($ck_url);//add http://

	 if($n_url == ($ck_url)){
	   $_SESSION['o_url'] = $o_url;
	   header("Location: ?url=".$black);	
	  }
	  
        }//end while loop

  //end check, everything cleared...

 //check for a youtube video...
  $link = parse_url($url);
      $youtube = $link['host'].$link['path'];
      $watch = "www.youtube.com/watch";
      $watch_2 = "youtube.com/watch";
      $watch_3 = "http://www.youtube.com/watch";
      $watch_4 = "http://youtube.com/watch";
  $qu = $link['query'];
  $qu = str_replace("v=", "", $qu);
  if ($youtube == $watch || $youtube == $watch_2 || $youtube == $watch_3 || $youtube == $watch_4) {
      print'<object width="425" height="349"><param name="movie" value="http://www.youtube.com/v/'.$qu.'&hl=en&fs=1&color1=0x006699&color2=0x54abd6&border=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'.$qu.'&hl=en&fs=1&color1=0x006699&color2=0x54abd6&border=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="349"></embed></object>'; }
  //end check for youtube video...
  
  //check for mp3 file...
   $string = $link['path'];
       $keyword = ".mp3";
   $keyword_1 = ".MP3";
       if (strpos($string, $keyword) > 0 || strpos($string, $keyword_1) > 0 ) {	   
   print'<object data="'.$url.'" type="application/x-mplayer2" width="200" height="50">
             <param name="src" value="'.$url.'">
             <param name="autoplay" value="false">
             <param name="autoStart" value="0">
             </object>';
        }
  //end check for mp3 file...
  
  echo $url;
  	  
}//pinged webpage, closing bracket.
}//url is not empty, closing bracket.



?>

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.