discussnow Posted November 21, 2008 Share Posted November 21, 2008 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 More sharing options...
DarkWater Posted November 21, 2008 Share Posted November 21, 2008 You have the function definition inside the if statement, which means it only gets defined why $_POST['para'] is set. Add the $scrape lines inside the if{ } block too. Link to comment https://forums.phpfreaks.com/topic/133613-undefined-function-error/#findComment-695114 Share on other sites More sharing options...
discussnow Posted November 21, 2008 Author Share Posted November 21, 2008 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> Link to comment https://forums.phpfreaks.com/topic/133613-undefined-function-error/#findComment-695120 Share on other sites More sharing options...
DarkWater Posted November 21, 2008 Share Posted November 21, 2008 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. Link to comment https://forums.phpfreaks.com/topic/133613-undefined-function-error/#findComment-695129 Share on other sites More sharing options...
discussnow Posted November 21, 2008 Author Share Posted November 21, 2008 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. Link to comment https://forums.phpfreaks.com/topic/133613-undefined-function-error/#findComment-695139 Share on other sites More sharing options...
DarkWater Posted November 21, 2008 Share Posted November 21, 2008 You didn't move the $scrape inside the if {}, you added it inside the function. Put it AFTER the function definition. Link to comment https://forums.phpfreaks.com/topic/133613-undefined-function-error/#findComment-695141 Share on other sites More sharing options...
discussnow Posted November 21, 2008 Author Share Posted November 21, 2008 You didn't move the $scrape inside the if {}, you added it inside the function. Put it AFTER the function definition. Ahhhh, Thanks! Link to comment https://forums.phpfreaks.com/topic/133613-undefined-function-error/#findComment-695142 Share on other sites More sharing options...
discussnow Posted November 21, 2008 Author Share Posted November 21, 2008 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> Link to comment https://forums.phpfreaks.com/topic/133613-undefined-function-error/#findComment-695144 Share on other sites More sharing options...
redarrow Posted November 21, 2008 Share Posted November 21, 2008 it a https website m8.... not sure but i think it make a diffrence....... Link to comment https://forums.phpfreaks.com/topic/133613-undefined-function-error/#findComment-695159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.