Link to home
Start Free TrialLog in
Avatar of FairyBusiness
FairyBusinessFlag for United States of America

asked on

Why is my $_GET variable coming up undefined??

Hi, I set 'clear' in my link:

<a href="logfile.php?clear=true">Clear Log File</a>

I try to get it:

if($_GET['clear'] == 'true') {
      file_put_contents($logfile, '');
      // Add the first log entry
      log_action('Logs Cleared', "by User Id {$session->user_id}");
      // redirect to this same pages so that the URL won't have "clear=true" anymore
      ob_end_clean();
      redirect_to('logfile.php');
}

But for some reason thats not working??  Anyone know why?

Notice: Undefined index: clear in /hermes/web09c/b2950/moo.auroriellacom/logfile.php on line 11
<?php
ini_set('display_errors' ,1); 
error_reporting(E_ALL);

require_once 'includes/library.php';
$title = "Auroriella Management";
include 'header.php';

$logfile = 'logs/logs.txt';

if($_GET['clear'] == 'true') {
	file_put_contents($logfile, '');
	// Add the first log entry
	log_action('Logs Cleared', "by User Id {$session->user_id}");
	// redirect to this same pages so that the URL won't have "clear=true" anymore
	ob_end_clean();
	redirect_to('logfile.php');
}

//validate_fields(); // Validation
find_selected_id(); // Needs to go below process_fields to show updates
echo nav($select_nav);

include 'sidebar.php';
echo menu($select_menu, $select_product, $select_metal);

include 'display.php';
//user_info();
?>
<a href="logfile.php?clear=true">Clear Log File</a>
<?php
echo "<p>";
if(file_exists($logfile) && is_readable($logfile) && $handle = fopen($logfile, 'r')) {
	echo "<ul class=\"logs\">";
	while(!feof($handle)) { // Until we get to the end of the file
		$entry = fgets($handle); // fgets works bc we know there are new lines
		if(trim($entry) != "") { // Trim white space and make sure its not nothing
			echo "<li>{$entry}</li>";
		}
	}
	echo "</ul>";
	fclose($handle);
}
else {
	echo "Could not read from {$logfile}.";
}
echo "<p>";

require 'footer.php';
?>

Open in new window

Avatar of Jagadishwor Dulal
Jagadishwor Dulal
Flag of Nepal image

Try using if(isset($_GET['clear']==true)) so that your can find the $_GET method have set a value to 'clear' or not
SOLUTION
Avatar of AielloJ
AielloJ
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FairyBusiness

ASKER

Thanks you guys! I had to end up doing this:

if(isset($_GET['clear']) && $_GET['clear'] == 1) {
      file_put_contents($logfile, '');
      // Add the first log entry
      log_action('Logs Cleared', "by User Id {$session->user_id}");
      // redirect to this same pages so that the URL won't have "clear=1" anymore
      ob_end_clean();
      redirect_to('logfile.php');
}