5 Replies - 4206 Views - Last Post: 30 January 2010 - 02:45 AM Rate Topic: -----

#1 d.buckner  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 04-December 08

$_GET index error

Posted 12 December 2009 - 08:25 AM

I am attempting to create a log file (following an online tutorial) everything seems to work but when I load the page I keep getting an Undefined Index error when the value is supposed to be true. This is to clear out the log, it does clear the log but throws the error as well. It works fine when the value is set to false.

Here is the relevant code:

 if(!$session->is_logged_in())
		{
			redirect_to("login.php");
		}
		$logfile = SITE_ROOT.DS.'logs'.DS.'log.txt';
		
		if ($_GET['clear'] == 'true')
			{
				file_put_contents($logfile, '');
				log_action('Logs Cleared', "by User ID {$session->user_id}.");
				redirect_to('logfile.php');
			}
		
?>

<?php
	include_layout_template('admin_header.php')
?>

<a href="index.php">&laquo; Back </a><br />
<br />

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



Is This A Good Question/Topic? 0
  • +

Replies To: $_GET index error

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,436
  • Joined: 23-August 08

Re: $_GET index error

Posted 12 December 2009 - 08:30 AM

So the url being passed looks like
myurl.php?clear=true?
Was This Post Helpful? 0
  • +
  • -

#3 d.buckner  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 04-December 08

Re: $_GET index error

Posted 12 December 2009 - 08:37 AM

View PostJackOfAllTrades, on 12 Dec, 2009 - 07:30 AM, said:

So the url being passed looks like
myurl.php?clear=true?



that is exactly what it looks like, but it does not load the page, it just gives me the undefined index error. I have tried to define the $_GET['clear'] variable to an empty value, but obviously that does not work as it keeps defining to nothing and never to the 'clear'=true. I do not know where to go from here.

This post has been edited by d.buckner: 12 December 2009 - 08:37 AM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,436
  • Joined: 23-August 08

Re: $_GET index error

Posted 12 December 2009 - 08:59 AM

Should work. Just did a quick example:
<?php

print_r($_GET);

if ($_GET['clear'] == 'true')
    print "It's true!";
else
    print "Nope, false it is!";
    
?>


With a url of /myfile.php I get:
Array ( )
Notice: Undefined index: clear in C:\wamp\www\myfile.php on line 5
Nope, false it is!

but with /myfile.php?clear=true:
Array ( [clear] => true ) It's true!


Are you using some rewrite rules maybe that could be messing with your url?

By the way, you should NEVER use a GET to modify data.
Was This Post Helpful? 0
  • +
  • -

#5 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: $_GET index error

Posted 12 December 2009 - 09:23 PM

try to use isset.
Example:
if(isset($_GET['clear']) && $_GET['clear']=="TRUE"){
// your code here...


Hope it helps :)
Was This Post Helpful? 0
  • +
  • -

#6 danielj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-January 10

Re: $_GET index error

Posted 30 January 2010 - 02:45 AM

View Postnoorahmad, on 12 Dec, 2009 - 08:23 PM, said:

try to use isset.
Example:
if(isset($_GET['clear']) && $_GET['clear']=="TRUE"){
// your code here...


Hope it helps :)


Hello,

I am getting the same error. I used
if(isset($_GET['clear']) && $_GET['clear']=="TRUE"){
and I don't have the error ( Undefined index: clear ) but it is not clearing the logs.
Any idea: Thanks for your reply.

DJ
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1