Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-14-2005, 12:35 PM   #1 (permalink)
gamehead200
Code Monkey
 
gamehead200's Avatar
 
Join Date: Oct 2004
Posts: 57
gamehead200 is an unknown quantity at this point
Undefined Index Errors

Hey guys,

Its been a long time since I was last on here, but I'm having trouble with a script I downloaded. Hopefully you guys can provide me with some help as the creator does not provide it anymore.

The script is a torrent indexer, not a tracker, written in PHP (similar to Mininova). Whenever I go to the admin page, I get a blank page. When I run the script in the PHP console, I get the following errors:

Quote:
PHP Notice: Undefined index: HTTP_HOST in c:\program files\apache group\apache2\htdocs\trackersoares\webtorrent\lib\ stdlib.php on line 134
PHP Notice: Undefined index: PATH_INFO in c:\program files\apache group\apache2\htdocs\trackersoares\webtorrent\lib\ stdlib.php on line 120
PHP Notice: Undefined variable: me in c:\program files\apache group\apache2\htdocs\trackersoares\webtorrent\lib\ stdlib.php on line 127
PHP Notice: Undefined index: HTTP_HOST in c:\program files\apache group\apache2\htdocs\trackersoares\webtorrent\lib\ stdlib.php on line 134
PHP Notice: Undefined index: PATH_INFO in c:\program files\apache group\apache2\htdocs\trackersoares\webtorrent\lib\ stdlib.php on line 120
PHP Notice: Undefined variable: me in c:\program files\apache group\apache2\htdocs\trackersoares\webtorrent\lib\ stdlib.php on line 127
I have also included a copy of the file causing the problem (which is open source):

stdlib.php
PHP Code:
<?
function hex2bin ($input$assume_safe=true)
{
    if (
$assume_safe !== true && ! ((strlen($input) % 2) === || preg_match ('/^[0-9a-f]+$/i'$input)))
        return 
"";
    return 
pack('H*'$input );
}
function 
setdefault(&$var$default="") {
/* if $var is undefined, set it to $default.  otherwise leave it alone */

    
if (! isset($var)) {
        
$var $default;
    }
}

function 
nvl(&$var$default="") {
/* if $var is undefined, return $default, otherwise return $var */

    
return isset($var) ? $var $default;
}

function 
evl(&$var$default="") {
/* if $var is empty, return $default, otherwise return $var */

    
return empty($var) ? $var $default;
}

function 
ov(&$var) {
/* returns $var with the HTML characters (like "<", ">", etc.) properly quoted,
 * or if $var is undefined, will return an empty string.  note this function
 * must be called with a variable, for normal strings or functions use o() */

    
return o(nvl($var));
}

function 
pv(&$var) {
/* prints $var with the HTML characters (like "<", ">", etc.) properly quoted,
 * or if $var is undefined, will print an empty string.  note this function
 * must be called with a variable, for normal strings or functions use p() */

    
p(nvl($var));
}

function 
o($var) {
/* returns $var with HTML characters (like "<", ">", etc.) properly quoted,
 * or if $var is empty, will return an empty string. */

    
return empty($var) ? "" htmlSpecialChars(stripslashes($var));
}

function 
p($var) {
/* prints $var with HTML characters (like "<", ">", etc.) properly quoted,
 * or if $var is empty, will print an empty string. */

    
echo o($var);
}

function 
jstring($var) {
/* returns string that is quoted for javascript */

    
return addslashes($var);
}

function 
db_query_loop($query$prefix$suffix$found_str$default="") {
/* this is an internal function and normally isn't called by the user.  it
 * loops through the results of a select query $query and prints HTML
 * around it, for use by things like listboxes and radio selections
 *
 * NOTE: this function uses dblib.php */

    
$output "";
    
$result db_query($query);
    while (list(
$val$label) = db_fetch_row($result)) {
        if (
is_array($default))
            
$selected = empty($default[$val]) ? "" $found_str;
        else
            
$selected $val == $default $found_str "";

        
$output .= "$prefix value='$val' $selected>$label$suffix";
    }

    return 
$output;
}

function 
db_listbox($query$default=""$suffix="\n") {
/* generate the <option> statements for a <select> listbox, based on the
 * results of a SELECT query ($query).  any results that match $default
 * are pre-selected, $default can be a string or an array in the case of
 * multi-select listboxes.  $suffix is printed at the end of each <option>
 * statement, and normally is just a line break */

    
return db_query_loop($query"<option"$suffix"selected"$default);
}

function 
strip_querystring($url) {
/* takes a URL and returns it without the querystring portion */

    
if ($commapos strpos($url'?')) {
        return 
substr($url0$commapos);
    } else {
        return 
$url;
    }
}

function 
get_referer() {
/* returns the URL of the HTTP_REFERER, less the querystring portion */

    
return strip_querystring(nvl($_SERVER["HTTP_REFERER"]));
}

function 
me() {
/* returns the name of the current script, without the querystring portion.
 * this function is necessary because PHP_SELF and REQUEST_URI and PATH_INFO
 * return different things depending on a lot of things like your OS, Web
 * server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.) */

    
if (isset($_SERVER["REQUEST_URI"])) {
        
$me $_SERVER["REQUEST_URI"];

    } elseif (
$_SERVER["PATH_INFO"]) {
        
$me $_SERVER["PATH_INFO"];

    } elseif (
$_SERVER["PHP_SELF"]) {
        
$me $_SERVER["PHP_SELF"];
    }

    return 
strip_querystring($me);
}

function 
qualified_me() {
/* like me() but returns a fully URL */

    
$protocol = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? "https://" "http://";
    
$url_prefix "$protocol$_SERVER[HTTP_HOST]";
    return 
$url_prefix me();
}

function 
match_referer($good_referer "") {
/* returns true if the referer is the same as the good_referer.  If
 * good_refer is not specified, use qualified_me as the good_referer */

    
if ($good_referer == "") { $good_referer qualified_me(); }
    return 
$good_referer == get_referer();
}

function 
redirect($url$message=""$delay=0) {
/* redirects to a new URL using meta tags */
    
echo "<meta http-equiv='Refresh' content='$delay; url=$url'>";
    if (!empty(
$message)) echo "<br><br><br><br><br><div style='font-family: Arial, Sans-serif; font-size: 20pt;' align=center>$message</div>";
    die;
}

function 
read_template($filename, &$var) {
/* return a (big) string containing the contents of a template file with all
 * the variables interpolated.  all the variables must be in the $var[] array or
 * object (whatever you decide to use).
 *
 * WARNING: do not use this on big files!! */

    
$temp str_replace("\\""\\\\"implode(file($filename), ""));
    
$temp str_replace('"''\"'$temp);
    eval(
"\$template = \"$temp\";");
    return 
$template;
}

function 
checked(&$var$set_value 1$unset_value 0) {
/* if variable is set, set it to the set_value otherwise set it to the
 * unset_value.  used to handle checkboxes when you are expecting them from
 * a form */

    
if (empty($var)) {
        
$var $unset_value;
    } else {
        
$var $set_value;
    }
}

function 
frmchecked(&$var$true_value "checked"$false_value "") {
/* prints the word "checked" if a variable is true, otherwise prints nothing,
 * used for printing the word "checked" in a checkbox form input */

    
if ($var) {
        echo 
$true_value;
    } else {
        echo 
$false_value;
    }
}

function 
mysql_timestamp($dt$blank="") {
/* returns formatted MySQL timestamp, or $blank if it's blank */

    
if (empty($dt)) return $blank;

    
$yr strval(substr($dt,0,4));
    
$mo strval(substr($dt,4,2));
    
$da strval(substr($dt,6,2));
    
$hr strval(substr($dt,8,2));
    
$mi strval(substr($dt,10,2));

    return 
date("m/d/Y"mktime($hr,$mi,0,$mo,$da,$yr));
}
function 
quote_smart($value)
{
   
// Stripslashes
   
if (get_magic_quotes_gpc()) {
       
$value stripslashes($value);
   }
   
// Quote if not integer
   
if (!is_numeric($value)) {
       
$value "'" mysql_real_escape_string($value) . "'";
   }
   return 
$value;
}

?>
Thanks.
gamehead200 is offline   Reply With Quote
Old 11-14-2005, 02:37 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
something like this: $_SERVER["PATH_INFO"] is what causes the problem, it is a global variable which should be available but for some reason it isn't on your system..
I dont remember how axactly you activate it, but think it might have something todo with register_globals settings for your PHP.. Or perhaps not..
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 11-14-2005, 04:47 PM   #3 (permalink)
gamehead200
Code Monkey
 
gamehead200's Avatar
 
Join Date: Oct 2004
Posts: 57
gamehead200 is an unknown quantity at this point
I just checked my phpinfo() page and it seems to be reporting the path fine for that particular file.
gamehead200 is offline   Reply With Quote
Old 11-14-2005, 07:54 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
you need to set your php.ini file to not display notices. displaying warnings and errors, but not notices is the most typical setup and what most people code for.

Code:
error_reporting  =  E_ALL & ~E_NOTICE
also, if you still run into problems, you may have to turn on register_globals. it's not as secure as having it off, but again, most servers are setup this way:

Code:
register_globals On
once you have made the changes in your php.ini file, restart your web server and you should be good to go.
sde is offline   Reply With Quote
Old 11-15-2005, 02:46 PM   #5 (permalink)
gamehead200
Code Monkey
 
gamehead200's Avatar
 
Join Date: Oct 2004
Posts: 57
gamehead200 is an unknown quantity at this point
Still having the same problems. However, I have brought it down to two errors. Lines 120 and 134. The error on line 127 was because it should have been else instead of elseif.
gamehead200 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
index Odoggy5 HTML, XML, Javascript, AJAX 1 10-03-2005 10:46 AM
Compile errors glennandrewcoop Standard C, C++ 3 04-17-2005 01:22 PM
javascript: check if file input is undefined sde HTML, XML, Javascript, AJAX 3 03-28-2005 09:15 AM
Suppressing errors with the cp command sde Linux / BSD / OS X 2 11-08-2004 11:15 AM
hashing help saiz66 Standard C, C++ 2 06-28-2004 02:39 AM


All times are GMT -8. The time now is 07:37 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting