works on local, does not work on server.

Discussion in 'PHP' started by baris22, Aug 3, 2007.

  1. #1
    this is so irritating.

    I do not have a big php knowledge. there are 2 files. search.php and settings.php.

    here is search.php

    
    
    include("setting.php");
    
    $yt = new YouTube;
    
    $columns = "1"; $rows = "20";
    $vpp = $columns * $rows;
    
    if (!$_GET[page]) { $Pages = 1; }
    else { $Pages = $_GET[page]; }
    $Search = $_GET[search];
    $yt->Search($Search, $Pages);
    $Results = $yt->Results();
    $Videos  = $yt->Videos();
    
    if ($_GET[s] == "mr") { $TotalPages = 15; }
    else { $TotalPages = 5; }
    
    
    displayVideos($Videos);
    
    $Next = $Pages + 1;
    $Previous = $Pages - 1;
    if ($Pages != 1) { echo '<a href="index.php?'.$Search.'&page='.$Previous.'" style="font-family:Tahoma, Arial, Helvetica, sans-serif; font-size:14px;">Previous</a>'; }
    $page = $Pages;
    $ipage = 5;
    if ($ipage > 1) {
    	for($z=-4; $z<$ipage; $z++) {
    		$tmp = $page+$z;
    		if ($tmp > 0 && $tmp <= $TotalPages) {
    			if ($tmp == $page)
    				echo '&nbsp;|&nbsp;<a href=\'search.php?search='.$Search.'&page='.$tmp.'\'" style="font-family:Tahoma, Arial, Helvetica, sans-serif; font-size:14px;">'.$tmp.'</a>';
    			else
    				echo '&nbsp;|&nbsp;<a href=\'search.php?search='.$Search.'&page='.$tmp.'\'" style="font-family:Tahoma, Arial, Helvetica, sans-serif; font-size:14px;">'.$tmp.'</a>';
    		}
    	}
    }
    if ($Pages < $TotalPages) { echo '&nbsp;|&nbsp;<a href="search.php?search='.$Search.'&page='.$Next.'" style="font-family:Tahoma, Arial, Helvetica, sans-serif; font-size:14px;">Next</a><br /><br /></div>'; }
    
    include("footer.php"); ?>
    
    
    PHP:
    this is the setting.php

    
    
    <?php
    
    
    function getVEntries($pageText){
    print $pageText;
    preg_match_all('|\<div class=\"v120vEntry\"\>(.*?)\<\/div\> \<\!-- end vEntry --\>|s',$pageText,$ventries);
    }
    
    CLASS YouTube {
    	var $_Results;
    	var $_ResultCount;
    	function Browse($select = "mp", $time = "t", $category = "0" , $page = "1") {
    		$results = file("http://www.youtube.com/browse?s=".$select."&t=".$time."&c=".$category."&l=&p=".$page);
    		$results = implode("", $results);
                    preg_match_all('|\<div class=\"v120vEntry\"\>(.*?)\<\/div\> \<\!-- end vEntry --\>|s',$results,$ventries);
                    $this->videos=array();
                    
                    foreach ($ventries[1] as $ventryText){
                      $this->videos[]=new vEntry($ventryText);
                    }
    	}
    	function Search($query, $page='1', $type='search_videos', $sort='relevance', $category = "0") {
                    $query=urlencode($query);
    		$url = "http://www.youtube.com/results?search_query=".$query."&page=".$page;
    		if ($category) { $url .= "&search_category=".$category; }
    		if ($sort) { $url .= "&search_sort=".$sort; }
    		if ($type) { $url .= "&search_type=".$type; }
    		$results = file($url);
    		$results = implode("", $results);
                    preg_match_all('|\<div class=\"vEntry\"\>(.*?)\<\/div\> \<\!-- end vEntry --\>|s',$results,$ventries);
                    $this->videos=array();
                    foreach ($ventries[1] as $ventryText){
                      $this->videos[]=new searchvEntry($ventryText);
                    }
    	}
    	function ResultCount() {
    		return $this->_ResultCount;
    	}
    	function Results() { 
    		return $this->_Results;
    	}
            function Videos() {
    		return $this->videos;
    	}
            function GetSearchResults($search_query, $page) {
                    return $this->Search($search_query,$page);
                    }
    
    }
    
    function displayVideos($Videos){
    $columns = "3"; $rows = "5";
    $vpp = $columns * $rows;
    
    echo '<table align="center" width="600" border="0" cellspacing="5" cellpadding="5" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;">';
    $i = 0;
    
              $video=$Videos[$i];
    for($r=0; $r<$rows; $r++) {
              $video=$Videos[$i];
    		echo '<tr>';
    		for($c=0; $c<$columns; $c++) {
    			echo '<td valign="top" width="130">';
            	        if($Videos[$i]){
                                      $video=$Videos[$i];
    				if ($_GET[s] == "mr") {
                                                              
    					echo '<a href="watch.php?video='.$video->url.'"><img src="'.$video->image.'" border="0" width="130" height="97" /><br />'.$video->title.'</a><br />';
    				}
    				else {
    					echo '<a href="watch.php?video='.$video->url.'"><img src="'.$video->image.'" border="0" width="130" height="97" /><br />'.$video->title.'</a><br />';
    				}
    			}
    			echo '</td>';
    			$i++;
    
    }
    }
    echo '</table><div align="right" style="padding-right: 25px">';
    }
    
    class searchvEntry{
    function __construct($text){
    $this->text=$text;
    preg_match('|<div class="vSnippetTitle">(.*?)\<a href=\"\/watch\?v=(.*?)\"\>(.*?)\<\/a\>|s',$this->text,$titles);
    $this->title=$titles[3];
    preg_match('|\<a href=\"\/watch\?v=(.*?)\"|',$this->text,$vid);
    $this->url=$vid[1]; //better new name
    preg_match('|img src=\"(.*?)\" border=\"0\" class=\"vimg120\"|s',$this->text,$images);
    $this->image=$images[1];
    preg_match('|\<span class=\"runtime\"\>(.*?)\<\/span\>|',$this->text,$runtimes);
    $this->runtime=$runtimes[1];
    preg_match('|\<span class=\"runtime\"\>(.*?)\<\/span\>|',$this->text,$postdates);
    $this->postdate=$postdates[1];
    preg_match_all('|\<img class=\"rating\" src=\"(.*?)\"|',$this->text,$stars,PREG_SET_ORDER);
    $this->views='';
    $this->star1=$stars[0][1];
    $this->star2=$stars[1][1];
    $this->star3=$stars[2][1];
    $this->star4=$stars[3][1];
    $this->star5=$stars[4][1];
    }
    }
    
    class vEntry{
    function vEntry($text){
    $this->text=$text;
    //preg_match('|div class=\"vtitle\"\>(.*?)\)\;\"\>(.*?)\<\/a\>\<\br\/\>|',$this->text,$titles);
    preg_match('|<div class="vtitle">(.*?)\<a href=\"\/watch\?v=(.*?)\"\>(.*?)\<\/a\>|s',$this->text,$titles);
    $this->title=$titles[3];
    preg_match('|\<a href=\"\/watch\?v=(.*?)\"|',$this->text,$vid);
    $this->video=$vid[1]; //silly old name
    $this->url=$vid[1]; //better new name
    preg_match('|<img src=\"(.*?)\" class=\" vimg \"|',$this->text,$images);
    $this->image=$images[1];
    preg_match('|\<span class=\"runtime\"\>(.*?)\<\/span\>|',$this->text,$runtimes);
    $this->runtime=$runtimes[1];
    preg_match('|\<span class=\"runtime\"\>(.*?)\<\/span\>|',$this->text,$postdates);
    $this->postdate=$postdates[1];
    preg_match_all('|\<img class=\"rating\" src=\"(.*?)\"|',$this->text,$stars,PREG_SET_ORDER);
    $this->views='';
    $this->star1=$stars[0][1];
    $this->star2=$stars[1][1];
    $this->star3=$stars[2][1];
    $this->star4=$stars[3][1];
    $this->star5=$stars[4][1];
    }
    
    
    }
    
    ?>
    
    
    PHP:
    Please help me.
     
    baris22, Aug 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Well... what error do you get? Or what exactly does not work?
     
    nico_swd, Aug 3, 2007 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    There is no error.

    There is no results on the search.
     
    baris22, Aug 3, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Try setting thee two lines on top of the current code.
    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    PHP:
    Now see if you get any errors.
     
    nico_swd, Aug 3, 2007 IP
  5. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    it said

    
    Notice: Use of undefined constant page - assumed 'page' in /home/content/b/a/r/baris22e/html/search.php on line 71
    
    Notice: Undefined index: page in /home/content/b/a/r/baris22e/html/search.php on line 71
    
    Notice: Use of undefined constant search - assumed 'search' in /home/content/b/a/r/baris22e/html/search.php on line 73
    
    Notice: Use of undefined constant s - assumed 's' in /home/content/b/a/r/baris22e/html/search.php on line 78
    
    Notice: Undefined index: s in /home/content/b/a/r/baris22e/html/search.php on line 78
    
    
    PHP:
     
    baris22, Aug 3, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    These errors are caused by poor coding. However, they should not prevent the script from working. Maybe your server doesn't run PHP 5, so try replacing this:
    
    class searchvEntry{
    function __construct($text){
    
    PHP:
    With:
    
    class searchvEntry{
    function searchvEntry($text){
    
    PHP:

    In setting.php
     
    nico_swd, Aug 3, 2007 IP
  7. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    Thank you very much

    nico_swd

    it is working now.



     
    baris22, Aug 3, 2007 IP
  8. klaus2

    klaus2 Member

    Messages:
    64
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #8
    Youtube changed the inner html. New parser is needed.
     
    klaus2, Jan 31, 2008 IP