Jump to content

undefined variable message


spdwrench

Recommended Posts

when I turned errors on in one of my php pages I got this error..

 

but the page still works fine..

 

I never had to declare a variable in php... why is it telling me I have an undefined?

 

I thought they were defined when you define them?

 

just wierd

 

Paul

Link to comment
Share on other sites

<?php
$nauth=0;
$nauth=$sAuth;
?>

 

undefined line 3

 

$sAuth is a variable that comes from another part of the site into the phpbb system

 

it works fine just wondering why says undefined? I thought it did not matter in php?

 

Paul

Link to comment
Share on other sites

At login set a session or cookie

 

 

in this case you mentioned cookies

 

setcookie("nameofcookie", "valueofcookie", time()+3600, "/", "yoursite.com", 1);

 

name of the cookie maybe be "users"

 

value could be under a field like "auth_lvl" ranging from 1-3 1 being a super admin and then down the line

 

do this in secure areas

 

if (!isset($_COOKIE['users'])) {

  header(); // send them somewhere else

  exit;

}

 

then to check auth_lvl

 

if ($_COOKIE['users'] != 1) {

  die("Unauthorized");

}

 

but $_SESSIONS are bettter to use

Link to comment
Share on other sites

As you said earlier, the page still works - so in that sense it does not matter. All it tells you is that you have used some bad coding practice... take this example:

 

script.php

<?php
error_reporting(E_ALL);

$id = $_GET['id'];

echo $id;
?>

 

If I call the script.php without the ID get argument PHP will throw a notice saying that I have an undefined index... all this means is that $_GET['id'] does not exist even though I'm using it. The end result is of course that $id will hold the value '' and nothing will be printed to the screen... fine. But it would be good practice to test for the existence of $_GET['id'] before using it.

 

if($_GET['id'])  {

    $id = $_GET['id'];

}

 

 

I know it's not the exact same thing, but it a similar case. If you wanna know exactly why it says undefined (which is only a part of the error - what is the rest?) you will have to post the whole error message :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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