dongpu8935 2014-09-12 21:03
浏览 39
已采纳

调用其他函数PHP [关闭]

I have a file myfunctions.php which has four functions. all functions when called perform some transaction to database. if im calling only one function from that page that is working fine. but if im calling two functions than only one top one(function that is called first) is working and other are not working.

myfunctions.php

<?php

include('includes/db.inc.php');

function blockip($ip,$attempts){
    global $mysqli;
    if(isset($ip) && $ip!=''){
        $query = 'INSERT INTO blockip VALUES(?,?)';
        if($stmt = $mysqli -> prepare($query)){
            $stmt -> bind_param('si',$ip,$attempts);
            $stmt -> execute();
            $stmt -> close();
        }
        $mysqli -> close();
    }else{
        echo $mysqli-> error();
    }
}
function getip($ip){
    global $mysqli;
    $ip_found =  null;
    if(isset($ip) && $ip!=''){
        $query = 'SELECT `ip` FROM `blockip` WHERE `ip`=?';
        if($stmt=$mysqli -> prepare($query)){
            $stmt -> bind_param('s',$ip);
            $stmt -> execute();
            $stmt -> bind_result($ipret);
            $stmt -> fetch();
            $stmt -> close();
            if($ipret!=null)
                $ip_found = $ipret;
            else
                $ip_fount = '';
        }
        $mysqli -> close();
    }
    return $ip_found;
}
?>

other functions at this file are also using $mysqli by declaring it global and all are of similar nature.

file at which im calling these functions login.php

<?php
session_start();
include('myfunctions.php');
$client_ip = $_SERVER['REMOTE_ADDR'];
?>

<!DOCTYPE html>
<html>
     <!-- Some HTML Code HERE -->
</html>
<?php
if($_SESSION['errorcode']==1){
    echo '<center> Invalid Captcha </center>';
}elseif($_SESSION['errorcode']==2){
    echo '<center> Invalid UserName / Password Combination </center>';
    trygetip($client_ip);
}
if($_SESSION['errorcode']==3){
    session_destroy();
    header('Location: 403.html');
    exit();
}
?>

my database file db.inc.php

<?php
error_reporting(0);
$db="xxxxxx";
$host="xxxxxx";
$username="xxxx";
$password="xxxx";
$mysqli =  new mysqli($host,$username,$password,$db);
if($mysqli->connect_error){
    die('Connection Failed : '.$mysqli-> connect_errno.' : '.$mysqli -> connect_error);
}
?>

now if i use two functions getip($someiphere) and than bockip($someiphere,$attempts) than 2nd one is not working and same issue with if i replace their position. thanx in advance

  • 写回答

2条回答 默认 最新

  • douxi3554 2014-09-12 21:06
    关注

    You close the mysql connection in both functions, just omit the $mysqli -> close();.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备