FairyBusiness
asked on
Why is my $_GET variable coming up undefined??
Hi, I set 'clear' in my link:
<a href="logfile.php?clear=tr ue">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.a uroriellac om/logfile .php on line 11
<a href="logfile.php?clear=tr
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.a
<?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';
?>
Try using if(isset($_GET['clear']==t rue)) so that your can find the $_GET method have set a value to 'clear' or not
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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') ;
}
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')
}