Jump to content

Undefined Function Error


discussnow

Recommended Posts

The issue seems to be that "file_get_the_contents($url) ; " is causing the error because it is not defined until after the function runs. I attempted to move the whole line below the function and as a result got a 403 error for the whole page.

 

<html>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<title> 
Link/Anchor Text Analyzer 
</title>
<body>  
Paste Website <br>
<textarea name="para" type="text" row="1" col="1">Here</textarea><br>
<input name="send" type="submit" value="Submit!">
<input type="reset" value="Cancel">
</body>
<?php
$para = $_GET['para'] ;
$url = "https://siteexplorer.search.yahoo.com/search?p=$para";
$scrape = file_get_the_contents($url) ;
if (isset($_Post['para'])){
function file_get_the_contents($url) {
  $ch = curl_init();
  $timeout = 10; // set to zero for no timeout
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $file_contents = curl_exec($ch);
  curl_close($ch);
  return $file_contents;
   }  
}

echo $scrape ;
?>
</html>

Link to comment
https://forums.phpfreaks.com/topic/133613-undefined-function-error/
Share on other sites

Did that, now i'm getting an unexpected T_IF error.

 

<html>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<title> 
Link/Anchor Text Analyzer 
</title>
<body>  
Paste Website <br>
<textarea name="para" type="text" row="1" col="1">Here</textarea><br>
<input name="send" type="submit" value="Submit!">
<input type="reset" value="Cancel">
</body>
<?php
$para = $_GET['para'] ;
$url = "https://siteexplorer.search.yahoo.com/search?p=$para";
$scraper = $scrape
if (isset($_Post['para'])){
function file_get_the_contents($url) {
  $ch = curl_init();
  $timeout = 10; // set to zero for no timeout
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $file_contents = curl_exec($ch);
  $scrape = file_get_the_contents($url) ;
  curl_close($ch);
  return $file_contents;
   }  
}

echo $scraper ;
?>
</html>

You missed a ;.  And you completely didn't understand what I just told you.  Move the exact $scaper = file_get_the_contents($url); line and the echo $scraper; line INSIDE the if block.

 

Ahh, thanks... I did move the $scrape inside the the if statement, just not the echo.

No errors but nothing is being echoed.

 

<html>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<title> 
Link/Anchor Text Analyzer 
</title>
<body>  
Paste Website <br>
<textarea name="para" type="text" row="1" col="1">Here</textarea><br>
<input name="send" type="submit" value="Submit!">
<input type="reset" value="Cancel">
</body>
<?php
$para = $_GET['para'] ;
$url = "https://siteexplorer.search.yahoo.com/search?p=$para";
if (isset($_Post['para'])){
function file_get_the_contents($url) {
  $ch = curl_init();
  $timeout = 10; // set to zero for no timeout
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $file_contents = curl_exec($ch);
  curl_close($ch);
  return $file_contents;
    }  
   $scrape = file_get_the_contents($url) ;
   echo $scrape ;
}


?>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.