PHP "include" error. How to solve?

Discussion in 'PHP' started by eches, May 8, 2008.

  1. #1
    Hello all,

    I installed linkworth code for my blog

    <?
    include('http://blog.eches.net/lw_rads.php?location=3&format=6');
    ?>
    Code (markup):
    but I got the following error

    Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/eches/public_html/blog/wp-content/themes/langit/rsidebar.php on line 42

    Warning: include(http://blog.eches.net/store/lw_rads.php?location=3&format=6) [function.include]: failed to open stream: no suitable wrapper could be found in /home/eches/public_html/blog/wp-content/themes/langit/rsidebar.php on line 42

    Warning: include() [function.include]: Failed opening 'http://blog.eches.net/store/lw_rads.php?location=3&format=6' for inclusion (include_path='.:/usr/local/php52/pear') in /home/eches/public_html/blog/wp-content/themes/langit/rsidebar.php on line 42

    I want to know the root cause of the problem. Is it from the code mentioned above or the the codes inside the lw_rads.php and how to fix the problem.

    lw_rads.php code

    <?
    	$file_name = "lw_rads.txt";
    
    	$location = $_GET['location'];
    	$format = $_GET['format'];
    	$nofollow = $_GET['nofollow'];
    
    	if($nofollow == 1)
    	{
    		$nofollow_attribute = 'rel=nofollow';
    	}
    	else
    	{
    		$nofollow_attribute = '';
    	}
    
    	$index = 0;
    	$handle = @fopen($file_name, "r");
    
    	if($handle)
    	{
    		$contents = @fread($handle, filesize($file_name));
    
    		if($contents)
    		{
    			fclose($handle);
    
    			$arr_lines = explode(chr(10), $contents);
    
    			for($i=0;$i<count($arr_lines);$i++)
    			{
    				$arr_deal = explode('|', $arr_lines[$i]);
    
    				if($arr_deal[1] == $location)
    				{
    					if($arr_deal[2] == 1)
    					{
    						$arr_anchors = explode('?,?', $arr_deal[3]);
    
    						$random_index = rand(0, count($arr_anchors) - 1);
    
    						$arr_data[$index]['anchor'] = $arr_anchors[$random_index];
    						$arr_data[$index]['url'] = $arr_deal[4];
    						$arr_data[$index]['desc'] = $arr_deal[5];
    					}
    					else
    					{
    						$arr_murl_infos = explode('?,?', $arr_deal[3]);
    
    						$random_index = rand(0, count($arr_murl_infos) - 1);
    
    						$str_murl_info = $arr_murl_infos[$random_index];
    
    						$arr_murl_info = explode('%,%', $str_murl_info);
    
    						$arr_data[$index]['anchor'] = $arr_murl_info[0];
    						$arr_data[$index]['url'] = $arr_murl_info[1];
    						$arr_data[$index]['desc'] = $arr_murl_info[2];
    					}
    
    					$index++;
    				}
    			}
    
    			if($arr_data)
    			{
    				$display_rads = true;
    			}
    		}
    	}
    
    
    	if($display_rads)
    	{
    		$num_rads = count($arr_data);
    
    		if($format == 1)
    		{
    			echo '<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">' . "\n";
    			echo '  <tr>' . "\n";
    			echo '    <td>' . "\n";
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				echo '<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					echo ' - ' . $arr_data[$i]['desc'];
    				}
    
    				if($i < ($num_rads - 1))
    				{
    					echo '<br/>' . "\n";
    				}
    			}
    
    			echo "\n" . '    </td>';
    			echo "\n" . '  </tr>' . "\n";
    			echo '</table>';
    		}
    		elseif($format == 2)
    		{
    		   echo '<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">' . "\n";
    			echo '  <tr>' . "\n";
    			echo '    <td>' . "\n";
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				echo '<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					echo ' - ' . $arr_data[$i]['desc'];
    				}
    
    				if($i < ($num_rads - 1))
    				{
    		         echo '   |||   ' . "\n";
    				}
    			}
    
    			echo "\n" . '    </td>';
    			echo "\n" . '  </tr>' . "\n";
    			echo '</table>';
    		}
    		elseif($format == 3)
    		{
    			echo '<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">' . "\n";
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				echo '  <tr>' . "\n";
    				echo '    <td>' . "\n";
    
    				echo '<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					echo ' - ' . $arr_data[$i]['desc'];
    				}
    
    				echo "\n" . '    </td>';
    				echo "\n" . '  </tr>' . "\n";
    			}
    
    		   echo '</table>';
    		}
    		elseif($format == 4)
    		{
    			for($i=0;$i<$num_rads;$i++)
    			{
    				echo '<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">';
    				echo '  <tr>' . "\n";
    				echo '    <td>' . "\n";
    
    				echo '<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					echo ' - ' . $arr_data[$i]['desc'];
    				}
    
    				echo "\n" . '    </td>';
    				echo "\n" . '  </tr>' . "\n";
    				echo '</table>';
    			}
    		}
    		elseif($format == 5)
    		{
    			echo '<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">';
    			echo '  <tr>' . "\n";
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				echo '    <td>' . "\n";
    
    				echo '<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					echo ' - ' . $arr_data[$i]['desc'];
    				}
    
    				echo "\n" . '    </td>';
    			}
    
    			echo "\n" . '  </tr>' . "\n";
    			echo '</table>';
    		}
    		elseif($format)
    		{
    			for($i=0;$i<$num_rads;$i++)
    			{
    				echo '<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					echo ' - ' . $arr_data[$i]['desc'];
    				}
    
    				echo $format . "\n";
    			}
    		}
    		else
    		{
    			echo '<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">';
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				echo '  <tr>' . "\n";
    				echo '    <td>' . "\n";
    
    				echo '<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					echo ' - ' . $arr_data[$i]['desc'];
    				}
    
    				echo "\n" . '    </td>';
    				echo "\n" . '  </tr>' . "\n";
    			}
    
    			echo '</table>';
    		}
    	}
    ?>
    Code (markup):
    Thanks in advance!
     
    eches, May 8, 2008 IP
  2. ilovelinux

    ilovelinux Peon

    Messages:
    285
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That's the real error. File access should be enabled by the server administrator.
     
    ilovelinux, May 8, 2008 IP
  3. relixx

    relixx Active Member

    Messages:
    946
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    70
    #3
    Normally the option to include files using a URL is disabled by default - you're essentially hotlinking to that file, with the same sort server resource problems you get when you hotlink to an image.

    Like ilovelinux said, you'll need to ask the server admin if they would activate this for you. If they don't, you'll have to find some other way to do the include, perhaps altering the code so that after you've included the file you pass the location and format variables to it
     
    relixx, May 8, 2008 IP
  4. eches

    eches Well-Known Member

    Messages:
    250
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #4
    I just learnt that new PHP version doesn't allow users to add URL, so I changed to the following but the problem persists

    <?php
    include('/home/eches/public_html/blog/lw_rads.php?location=3&format=6');
    ?>
    Code (markup):
    Any reference I should to take a look to solve the problem?
     
    eches, May 8, 2008 IP
  5. bokiatenxi

    bokiatenxi Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi eches83,

    first of all, I'm not sure if you could add a query string when using the include function, have you done that before? I ussually use the include function without a query string. If I am not mistaken, the include function requires a path to the file/filename and not a URL, that means adding a query string is impossible.

    if i am not correct, you should try checking the path, keep in mind that it is relative to the path of the file that uses the include function and not the root directory..

    hope this helps.. :D
     
    bokiatenxi, May 8, 2008 IP
  6. relixx

    relixx Active Member

    Messages:
    946
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    70
    #6
    Hey eches83,

    AFAIK you can't add query strings to an include like that, as include() was never designed to handle GET and POST data.

    Why not place the code in the lw_rads.php into a function in that file, then do something like:

    
    <?php
    include('path/to/lw_rads.php');
    $lw_rads = lw_rads_function(3, 6, 1); // 3,6,1 being examples for $location, $format, $nofollow
    echo $lw_rads;
    ?>
    
    PHP:
    The lw_rads.php file would have the following changes:

    <?php
    function lw_rads_function($location_var, $format_var, $nofollow_var) {
    
    $file_name = "lw_rads.txt";
    $location = $location_var;
    $format = $format_var;
    $nofollow = $nofollow_var;
    
    [rest of the code in the file stays the same]
    
    } // closing bracket for function
    ?>
    PHP:
     
    relixx, May 8, 2008 IP
  7. relixx

    relixx Active Member

    Messages:
    946
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    70
    #7
    Whoops, my bad, that function probably won't return any data. Let me fix that quick.

    Ok, fixed.

    Replace the entire if($display_rads) statement with the following:

    	if($display_rads)
    	{
    		$num_rads = count($arr_data);
    
    		if($format == 1)
    		{
    			$html .='<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">' . "\n";
    			$html .='  <tr>' . "\n";
    			$html .='    <td>' . "\n";
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				$html .='<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					$html .=' - ' . $arr_data[$i]['desc'];
    				}
    
    				if($i < ($num_rads - 1))
    				{
    					$html .='<br/>' . "\n";
    				}
    			}
    
    			$html .="\n" . '    </td>';
    			$html .="\n" . '  </tr>' . "\n";
    			$html .='</table>';
    		}
    		elseif($format == 2)
    		{
    		   $html .='<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">' . "\n";
    			$html .='  <tr>' . "\n";
    			$html .='    <td>' . "\n";
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				$html .='<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					$html .=' - ' . $arr_data[$i]['desc'];
    				}
    
    				if($i < ($num_rads - 1))
    				{
    		         $html .='   |||   ' . "\n";
    				}
    			}
    
    			$html .="\n" . '    </td>';
    			$html .="\n" . '  </tr>' . "\n";
    			$html .='</table>';
    		}
    		elseif($format == 3)
    		{
    			$html .='<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">' . "\n";
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				$html .='  <tr>' . "\n";
    				$html .='    <td>' . "\n";
    
    				$html .='<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					$html .=' - ' . $arr_data[$i]['desc'];
    				}
    
    				$html .="\n" . '    </td>';
    				$html .="\n" . '  </tr>' . "\n";
    			}
    
    		   $html .='</table>';
    		}
    		elseif($format == 4)
    		{
    			for($i=0;$i<$num_rads;$i++)
    			{
    				$html .='<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">';
    				$html .='  <tr>' . "\n";
    				$html .='    <td>' . "\n";
    
    				$html .='<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					$html .=' - ' . $arr_data[$i]['desc'];
    				}
    
    				$html .="\n" . '    </td>';
    				$html .="\n" . '  </tr>' . "\n";
    				$html .='</table>';
    			}
    		}
    		elseif($format == 5)
    		{
    			$html .='<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">';
    			$html .='  <tr>' . "\n";
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				$html .='    <td>' . "\n";
    
    				$html .='<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					$html .=' - ' . $arr_data[$i]['desc'];
    				}
    
    				$html .="\n" . '    </td>';
    			}
    
    			$html .="\n" . '  </tr>' . "\n";
    			$html .='</table>';
    		}
    		elseif($format)
    		{
    			for($i=0;$i<$num_rads;$i++)
    			{
    				$html .='<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					$html .=' - ' . $arr_data[$i]['desc'];
    				}
    
    				$html .=$format . "\n";
    			}
    		}
    		else
    		{
    			$html .='<table cellspacing="0" cellpadding="0" width="95%" border="0" class="lw">';
    
    			for($i=0;$i<$num_rads;$i++)
    			{
    				$html .='  <tr>' . "\n";
    				$html .='    <td>' . "\n";
    
    				$html .='<a class="lw" href="http://' . $arr_data[$i]['url'] . '" ' . $nofollow_attribute . ' target="_blank">' . $arr_data[$i]['anchor'] . '</a>';
    
    				if($arr_data[$i]['desc'])
    				{
    					$html .=' - ' . $arr_data[$i]['desc'];
    				}
    
    				$html .="\n" . '    </td>';
    				$html .="\n" . '  </tr>' . "\n";
    			}
    
    			$html .='</table>';
    		}
    	return $html;
    	}else{
    	return '';
    	}
    PHP:
     
    relixx, May 8, 2008 IP