Urgent: PHP undefined variable causing problems

7 replies
I need this fixed ASAP. PM me what you charge for it and where to send the money.

Here's the code:
<?php

if(!empty($_GET)) extract($_GET);
if(!empty($_POST)) extract($_POST);

function chk( $var, $default )
{
if ( !isset($var) )
{
echo $default;
}
else
{
if($var==single)
{
if(!empty($_SERVER["QUERY_STRING"])) {
$val = preg_replace("/[^0-9a-z -#]/i","", $_SERVER["QUERY_STRING"]);
echo trim($val); }
else
{
echo $default;
} } else { echo stripslashes($var);
}
}
}
?>
It's returning undefined variable errors, and they're getting inserted in the POST data for the form on the page it's used in. Once per line that contains:

<?chk($page,"1");?>
That's screwing up tracking, which I can allow to happen for very long at all.

Suggestions?


Paul
#causing #php #problems #undefined #urgent #variable
  • Profile picture of the author mywebwork
    Hi Paul

    I really didn't look at it too hard so I might just be missing something obvious, but what purpose does "single" have in the following line:

    if(==single)
    Just wondering if it was a predefined constant (traditionally they are in uppercase), another variable (in which case it's missing the preceding $ sign) or a string (in which case it needs quotes around it).

    Again this might be totally irrelevant, but it just caught my eye.

    All the best...

    Bill
    {{ DiscussionBoard.errors[662142].message }}
    • Profile picture of the author Paul Myers
      Bill,

      I have absolutely no idea. I didn't write the code. I'm, not a programmer...


      Paul
      Signature
      .
      Stop by Paul's Pub - my little hangout on Facebook.

      {{ DiscussionBoard.errors[662584].message }}
      • Profile picture of the author Paul Myers
        If it helps in diagnosing it, here's the sequence of events that led up to the problem.

        My host "upgraded" my server to PHP 5.2. In the process, they overwrote all or part of php.ini.

        Ion Cube Loader stopped working/became inaccessible to server-side software. They fixed that, and Zend went away/became inaccessible. They reinstalled Zend, and the server started throwing "undefined variable" errors for a bunch of stuff that had been working right along.

        Each problem was the direct result of the preceding event.

        The problem does not appear to be register_globals, as I tried turning that on, and no effect.

        It's probably a system setting, but I can't figure out which one. But it may be in the code above.

        Everywhere that function call is placed in the page throws an error.

        Here's basically what that code does?

        You set a default value for "page"

        If the script is called with a query string, page=xyz, it puts xyz where the function call is placed in the page. If not, it inserts the default.

        The errors:

        PHP Notice: Use of undefined constant single - assumed 'single' in /home/paul/www/talkbiz.com/index.php on line 14

        PHP Notice: Undefined variable: page in /home/paul/www/talkbiz.com/index.php on line 49

        I think I fixed the first one by putting single quotes around single.

        The second is the big one. That's what's getting thrown by all sorts of stuff that didn't before the "upgrade."


        Paul
        Signature
        .
        Stop by Paul's Pub - my little hangout on Facebook.

        {{ DiscussionBoard.errors[662651].message }}
  • Profile picture of the author RedMatrix
    I think we need to see your index.php file, specifically the code block that includes line 49. (sometimes an error is on the previous "line" number)
    Signature

    ~Dave

    {{ DiscussionBoard.errors[663408].message }}
  • Profile picture of the author n7 Studios
    You've not included the relevent code to do with your second error. Your options are:
    - find the page variable, and use the isset() function before performing any operations on it, or
    - use error_reporting(247) to switch off undefined variable errors (not recommended, but a quick fix)
    {{ DiscussionBoard.errors[664151].message }}
    • Profile picture of the author Paul Myers
      That little tag at the end of the post is what appears on the lines where the error was noted.

      It's been fixed. Don (zerofill) whipped up a substitute bit of code that's much smaller, cleaner, and does the job.

      Thanks to all. Especially the person who gave me the error reporting suppression code, which cured the symptom and gave me more time to fix the problem.


      Paul
      Signature
      .
      Stop by Paul's Pub - my little hangout on Facebook.

      {{ DiscussionBoard.errors[667786].message }}
    • Profile picture of the author jackpot9
      *posted in wrong thread*
      {{ DiscussionBoard.errors[6642754].message }}

Trending Topics