Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-23-2010, 08:41 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default SQL PHP Help needed "urgent"

i have this statement in a php file but keeps throwing up some error can someon eplease look over this code and get back to me with any morrections needed



Code:
$sql = "INSERT INTO `list` SET ";
$sql .= "`stamp`='" . sql_escape_string($stamp) . "', ";
$sql .= "`ip`='" . sql_escape_string($ip) . "', ";
$sql .= "`type`='" . sql_escape_string($type) . "', ";
$sql .= "`threat`='" . sql_escape_string($threat) . "', ";
$sql .= "`datetime`=now() ";
$r = sql_command($sql);
if ($r == 1) {
########################################
# good insertion, get record id number #
########################################
$id = sql_insert_id("list", "id");
return $id;
}
 
function sql_command ($sql) {
if (mysql_query($sql)) return mysql_affected_rows();
return -1;
}
 
function sql_insert_id($table, $field) {
return mysql_insert_id();
}
 
function sql_escape_string ($string) {
if (get_magic_quotes_gpc()) {
$string = stripslashes($string);
}
$string = mysql_real_escape_string($string);
return $string;
}

thank you
Reply With Quote
  #2  
Old 01-25-2010, 01:41 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It would help a lot of you would opst the error message and the linenumber on which it occurs.
Reply With Quote
  #3  
Old 01-25-2010, 02:38 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this is the full code i used in the php plugin

PHP Code:
 
/*
Script Name: Simple PHP http:BL implementation
Description: Simple script to check an IP against Project Honey Pot's database and let only legitimate users access your script
*/
if ($vbulletin->options['pro_honey_active']){
    if (
$_COOKIE['notabot']) {
        
ozh_httpbl_logme(false,    $_SERVER['REMOTE_ADDR']);
    } else {
        
ozh_httpbl_check();
    }
}
function 
ozh_httpbl_check() {
    global 
$vbulletin;    
    
$apikey $vbulletin->options[pro_honey_api];
    
// IP to test
    
$ip $_SERVER['REMOTE_ADDR'];
    
// build the lookup DNS query
    // Example : for '127.9.1.2' you should query 'abcdefghijkl.2.1.9.127.dnsbl.httpbl.org'
    
$lookup $apikey '.' implode('.'array_reverse(explode ('.'$ip ))) . '.dnsbl.httpbl.org';
    
    
// check query response
    
$result explode'.'gethostbyname($lookup));
    
    if (
$result[0] == 127) {
        
// query successful !
        
$activity $result[1];
        
$threat $result[2];
        
$type $result[3];
        
        if (
$type 0$typemeaning .= 'Search Engine, ';
        if (
$type 1$typemeaning .= 'Suspicious, ';
        if (
$type 2$typemeaning .= 'Harvester, ';
        if (
$type 4$typemeaning .= 'Comment Spammer, ';
        
$typemeaning trim($typemeaning,', ');
        
        
// echo "$type : $typemeaning of level $threat ";
        
        // Now determine some blocking policy
        
if (
        (
$type >= && $threat 0// Comment spammer with any threat level
            
||
        (
$type && $threat 20// Other types, with threat level greater than 20
        
) {
            
$block true;
        }
        
        if (
$block) {
            
ozh_httpbl_logme($block,$ip,$type,$threat,$activity);
            
ozh_httpbl_blockme();
            die();
        }
    
    }
}

function 
ozh_httpbl_logme($block false$ip=''$type='',$threat='',$activity='') {

);
    
$stamp date('d-m-Y :: H-i$sql = "INSERT INTO `list` SET ";
$sql .= "`stamp`='" . sql_escape_string(
$stamp) . "', ";
$sql .= "`ip`='" . sql_escape_string(
$ip) . "', ";
$sql .= "`type`='" . sql_escape_string(
$type) . "', ";
$sql .= "`threat`='" . sql_escape_string(
$threat) . "', ";
$sql .= "`datetime`=now() ";
$r = sql_command($sql);
if ($r == 1) {
########################################
# good insertion, get record id number #
########################################
$id = sql_insert_id("list", "id");
return $id;
}
 
function sql_command ($sql) {
if (mysql_query($sql)) return mysql_affected_rows();
return -1;
}
 
function sql_insert_id($table, $field) {
return mysql_insert_id();
}
 
function sql_escape_string ($string) {
if (get_magic_quotes_gpc()) {
$string = stripslashes($string);
}
$string = mysql_real_escape_string($string);
return $string;
}-s'
);
    
    
// Some stuff you could log for further analysis
    
$page $_SERVER['REQUEST_URI'];
    
$ua $_SERVER["HTTP_USER_AGENT"];
        
    if (
$block) {
        
fputs($log,"$stamp :: BLOCKED $ip :: $type :: $threat :: $activity :: $page :: $ua\n");
    } else {
        
fputs($log,"$stamp :: UNBLCKD $ip :: $page :: $ua\n");
    }
    
fclose($log);
}
function 
ozh_httpbl_blockme() {
    
header('HTTP/1.0 403 Forbidden');
    echo <<<HTML
    <script type="text/javascript">
    function setcookie( name, value, expires, path, domain, secure ) {
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );
    
        if ( expires ) {
            expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (expires) );
    
        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
    }    
    function letmein() {
        setcookie('notabot','true',1,'/', '', '');
        location.reload(true);
    }
    </script>
    <h1>Forbidden</h1>
    <p>Sorry. You are using a suspicious IP.</p>
    <p>Your IP address has been listed at <a href="http://www.projecthoneypot.org">http://www.projecthoneypot.org</a></p>
    <p>If you <strong>ARE NOT</strong> a bot of any kind, please <a href="javascript:letmein()">click here</a> to access the page. Sorry for this !</p> 
HTML;


the error i get is


Parse error: syntax error, unexpected ')' in /public_html/includes/functions.php(6505) : eval()'d code on line 73

plugin is set to
global_complete
Reply With Quote
  #4  
Old 01-25-2010, 03:09 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This line doesn't look correct:
PHP Code:
    $stamp date('d-m-Y :: H-i$sql = "INSERT INTO `list` SET "; 
Reply With Quote
  #5  
Old 01-25-2010, 03:39 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
This line doesn't look correct:
PHP Code:
    $stamp date('d-m-Y :: H-i$sql = "INSERT INTO `list` SET "; 

i have now corrected the php plugin code to this


PHP Code:
 
/*
Script Name: Simple PHP http:BL implementation
Description: Simple script to check an IP against Project Honey Pot's database and let only legitimate users access your script
*/
if ($vbulletin->options['pro_honey_active']){
    if (
$_COOKIE['notabot']) {
        
ozh_httpbl_logme(false,    $_SERVER['REMOTE_ADDR']);
    } else {
        
ozh_httpbl_check();
    }
}
function 
ozh_httpbl_check() {
    global 
$vbulletin;    
    
$apikey $vbulletin->options[pro_honey_api];
    
// IP to test
$ip "94.102.63.90";
    
// build the lookup DNS query
    // Example : for '127.9.1.2' you should query 'abcdefghijkl.2.1.9.127.dnsbl.httpbl.org'
    
$lookup $apikey '.' implode('.'array_reverse(explode ('.'$ip ))) . '.dnsbl.httpbl.org';
    
    
// check query response
    
$result explode'.'gethostbyname($lookup));
    
    if (
$result[0] == 127) {
        
// query successful !
        
$activity $result[1];
        
$threat $result[2];
        
$type $result[3];
        
        if (
$type 0$typemeaning .= 'Search Engine, ';
        if (
$type 1$typemeaning .= 'Suspicious, ';
        if (
$type 2$typemeaning .= 'Harvester, ';
        if (
$type 4$typemeaning .= 'Comment Spammer, ';
        
$typemeaning trim($typemeaning,', ');
        
        
// echo "$type : $typemeaning of level $threat ";
        
        // Now determine some blocking policy
        
if (
        (
$type >= && $threat 0// Comment spammer with any threat level
            
||
        (
$type && $threat 20// Other types, with threat level greater than 20
        
) {
            
$block true;
        }
        
        if (
$block) {
            
ozh_httpbl_logme($block,$ip,$type,$threat,$activity);
            
ozh_httpbl_blockme();
            die();
        }
    
    }
}
function 
ozh_httpbl_logme($block false$ip=''$type='',$threat='',$activity='') {
$sql "INSERT INTO `list` SET ";
$sql .= "`stamp`='" sql_escape_string($stamp) . "', ";
$sql .= "`ip`='" sql_escape_string($ip) . "', ";
$sql .= "`type`='" sql_escape_string($type) . "', ";
$sql .= "`threat`='" sql_escape_string($threat) . "', ";
$sql .= "`datetime`=now()";
$r sql_command($sql);
if (
$r == 1) {
########################################
# good insertion, get record id number #
########################################
$id sql_insert_id("list""id");
return 
$id;
}
function 
sql_command ($sql) {
if (
mysql_query($sql)) return mysql_affected_rows();
return -
1;
}
function 
sql_insert_id($table$field) {
return 
mysql_insert_id();
}
function 
sql_escape_string ($string) {
if (
get_magic_quotes_gpc()) {
$string stripslashes($string);
}
$string mysql_real_escape_string($string);
return 
$string;
}
    
    
// Some stuff you could log for further analysis
    
$page $_SERVER['REQUEST_URI'];
    
$ua $_SERVER["HTTP_USER_AGENT"];
        
    if (
$block) {
        
fputs($log,"$stamp :: BLOCKED $ip :: $type :: $threat :: $activity :: $page :: $ua\n");
    } else {
        
fputs($log,"$stamp :: UNBLCKD $ip :: $page :: $ua\n");
    }
    
fclose($log);
}
function 
ozh_httpbl_blockme() {
    
header('HTTP/1.0 403 Forbidden');
    echo <<<HTML
    <script type="text/javascript">
    function setcookie( name, value, expires, path, domain, secure ) {
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );
    
        if ( expires ) {
            expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (expires) );
    
        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
    }    
    function letmein() {
        setcookie('notabot','true',1,'/', '', '');
        location.reload(true);
    }
    </script>
    <h1>Forbidden</h1>
    <p>Sorry. You are using a suspicious IP.</p>
    <p>Your IP address has been listed at <a href="http://www.projecthoneypot.org">http://www.projecthoneypot.org</a></p>
    <p>If you <strong>ARE NOT</strong> a bot of any kind, please <a href="javascript:letmein()">click here</a> to access the page. Sorry for this !</p> 
HTML;



the error i now get is


Fatal error: Call to undefined function sql_escape_string() in /public_html/includes/functions.php(6505) : eval()'d code on line 68


i think it refere to this

########################################
# good insertion, get record id number #
########################################
$id = sql_insert_id("list", "id");
return $id;
}

not sure how to corect it
Reply With Quote
  #6  
Old 01-25-2010, 04:00 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I know there is a mysql call mysql_insert_id, but I don't know anything about just sql_insert_id. It doesn't take any parameters, I don't believe. It just returns the last increment used. Why aren't you just using standard vB mysql syntax?
Reply With Quote
  #7  
Old 01-25-2010, 04:14 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

because i am unsure how to do that

the sql code is an upade scrpt, logs ip address from projecthoneypot
if your listed

thats what i am try to do

i have no idea how to convert php sql to vb syntax

can you help
Reply With Quote
  #8  
Old 01-25-2010, 05:16 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, it was just more of a question, I didn't realize you didn't write the code. I think I would just try changing the line to mysql_insert_id() and see if that works. Looking at the function, it isn't clear why he passes those parameters in the first place.

Are you allowed to reuse this code?
Reply With Quote
  #9  
Old 01-25-2010, 05:43 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yep

i am in contact withe the guy who created the code i just request help to change it to sql

--------------- Added [DATE]1264449484[/DATE] at [TIME]1264449484[/TIME] ---------------

thank you for that a new issue has shown


PHP Code:
 
 
/*
Script Name: Simple PHP http:BL implementation
Description: Simple script to check an IP against Project Honey Pot's database and let only legitimate users access your script
*/
if ($vbulletin->options['pro_honey_active']){
    if (
$_COOKIE['notabot']) {
        
ozh_httpbl_logme(false,    $_SERVER['REMOTE_ADDR']);
    } else {
        
ozh_httpbl_check();
    }
}
function 
ozh_httpbl_check() {
    global 
$vbulletin;    
    
$apikey $vbulletin->options[pro_honey_api];
    
// IP to test
$ip "94.102.63.90";
    
// build the lookup DNS query
    // Example : for '127.9.1.2' you should query 'abcdefghijkl.2.1.9.127.dnsbl.httpbl.org'
    
$lookup $apikey '.' implode('.'array_reverse(explode ('.'$ip ))) . '.dnsbl.httpbl.org';
    
    
// check query response
    
$result explode'.'gethostbyname($lookup));
    
    if (
$result[0] == 127) {
        
// query successful !
        
$activity $result[1];
        
$threat $result[2];
        
$type $result[3];
        
        if (
$type 0$typemeaning .= 'Search Engine, ';
        if (
$type 1$typemeaning .= 'Suspicious, ';
        if (
$type 2$typemeaning .= 'Harvester, ';
        if (
$type 4$typemeaning .= 'Comment Spammer, ';
        
$typemeaning trim($typemeaning,', ');
        
        
// echo "$type : $typemeaning of level $threat ";
        
        // Now determine some blocking policy
        
if (
        (
$type >= && $threat 0// Comment spammer with any threat level
            
||
        (
$type && $threat 20// Other types, with threat level greater than 20
        
) {
            
$block true;
        }
        
        if (
$block) {
            
ozh_httpbl_logme($block,$ip,$type,$threat,$activity);
            
ozh_httpbl_blockme();
            die();
        }
    
    }
}
function 
ozh_httpbl_logme($block false$ip=''$type='',$threat='',$activity='') {
$sql "INSERT INTO `list` SET ";
$sql .= "`stamp`='" sql_escape_string($stamp) . "', ";
$sql .= "`ip`='" sql_escape_string($ip) . "', ";
$sql .= "`type`='" sql_escape_string($type) . "', ";
$sql .= "`threat`='" sql_escape_string($threat) . "', ";
$sql .= "`datetime`=now()";
$r sql_command($sql);
if (
$r == 1) {
########################################
# good insertion, get record id number #
########################################
mysql_insert_id()
return 
$id;
}
function 
sql_command ($sql) {
if (
mysql_query($sql)) return mysql_affected_rows();
return -
1;
}
function 
sql_insert_id($table$field) {
return 
mysql_insert_id();
}
function 
sql_escape_string ($string) {
if (
get_magic_quotes_gpc()) {
$string stripslashes($string);
}
$string mysql_real_escape_string($string);
return 
$string;
}
    
    
// Some stuff you could log for further analysis
    
$page $_SERVER['REQUEST_URI'];
    
$ua $_SERVER["HTTP_USER_AGENT"];
        
    if (
$block) {
        
fputs($log,"$stamp :: BLOCKED $ip :: $type :: $threat :: $activity :: $page :: $ua\n");
    } else {
        
fputs($log,"$stamp :: UNBLCKD $ip :: $page :: $ua\n");
    }
    
fclose($log);
}
function 
ozh_httpbl_blockme() {
    
header('HTTP/1.0 403 Forbidden');
    echo <<<HTML
    <script type="text/javascript">
    function setcookie( name, value, expires, path, domain, secure ) {
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );
    
        if ( expires ) {
            expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (expires) );
    
        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
    }    
    function letmein() {
        setcookie('notabot','true',1,'/', '', '');
        location.reload(true);
    }
    </script>
    <h1>Forbidden</h1>
    <p>Sorry. You are using a suspicious IP.</p>
    <p>Your IP address has been listed at <a href="http://www.projecthoneypot.org">http://www.projecthoneypot.org</a></p>
    <p>If you <strong>ARE NOT</strong> a bot of any kind, please <a href="javascript:letmein()">click here</a> to access the page. Sorry for this !</p> 
HTML;




Parse error: syntax error, unexpected T_RETURN in /public_html/includes/functions.php(6505) : eval()'d code on line 78
Reply With Quote
  #10  
Old 01-25-2010, 09:58 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need a ; at the end of the line.
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 11:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04648 seconds
  • Memory Usage 2,388KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete