第一次加载用户时的空白页面

时间:2014-07-10 11:44:55

标签: php mysql

每次第一次加载时我都会得到一个空白页面。只有当访问者(的IP)不在数据库中时才会发生这种情况。

这些也是我收到的错误,我也尝试删除这些行以查看问题是否在那里。 :

注意:未定义索引:参考/home /*/public_html/share2.php第32行

注意:未定义的索引:我们在第33行的/home/*/public_html/share2.php

注意:未定义的索引:第34行/home/*/public_html/share2.php中的ns

不推荐使用:函数sql_regcase()在第38行的/home/*/public_html/share2.php中已弃用

不推荐使用:第45行/home/*/public_html/share2.php中不推荐使用函数sql_regcase()

不推荐使用:第52行的/home/*/public_html/share2.php中不推荐使用函数sql_regcase()

//MySQL Connect
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
echo "<!-- MySQL connected -->";

//Initialize functions
function RandomString() {
    $length = 15;
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $string = "";    
    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand (0, strlen ($characters))];
    }
    return $string;
}
echo "<!-- Randomstring function loaded -->";

//Get inurl variables
$refid = $_GET['ref'];
$updateskin = $_GET['us'];
$newskin = $_GET['ns'];
echo "<!-- Inurl vars have been retrieved -" . $refid . ", " . $updateskin . ", " . $newskin . " -->";

//Make sure $refid is clean
$refid = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$refid); 
$refid = trim($refid); 
$refid = strip_tags($refid); 
$refid = addslashes($refid); 
echo "<!-- Refid cleaned - " . $refid . " -->";

//Make sure $updateskin is clean
$updateskin = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$updateskin); 
$updateskin = trim($updateskin); 
$updateskin = strip_tags($updateskin); 
$updateskin = addslashes($updateskin); 
echo "<!-- updateskin cleaned - " . $updateskin . " -->";

//Make sure $newskin is clean
$newskin = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$newskin); 
$newskin = trim($newskin); 
$newskin = strip_tags($newskin); 
$newskin = addslashes($newskin); 
echo "<!-- newskin cleaned - " . $newskin . " -->";


//Client data
$clientip = $_SERVER['REMOTE_ADDR'];
$clientbrowser = $_SERVER['HTTP_USER_AGENT'];
$clientrefurl = $_SERVER['HTTP_REFERER'];
echo "<!-- Retrieved servervars -->";

//Check if ip is already in database
$sql = "SELECT * FROM ref WHERE ip = '$clientip'";
$result = mysql_query($sql);
echo "<!-- IP check query-->";

//Prevent the script from failing if there was a MySQL error
if ( false === $result ) {
    echo mysql_error();
    echo "<!-- MYSQL ERROR -->";
}

//Check number of results to see if they IP is already in the db
$numrows = mysql_num_rows($result);

//If the IP is not in the database yet
if ($numrows == 0)
{
$id = RandomString();
$ip = $clientip;
$hits = 0;
$firsthitdate = date("d-m-Y H:i:s"); 
$browser = $clientbrowser;
$refurl = $clientrefurl;
$sql = "INSERT INTO ref (id, ip, hits, firsthitdate, browser, refurl) VALUES('$id', '$ip', '$hits', '$firsthitdate', '$browser', '$refurl')";
$result = mysql_query($sql)or die(mysql_error());


if (isset($refid) === false)
{
$refid = "noref";
}
$sql = "SELECT * FROM ref WHERE id = '$refid'";
$result = mysql_query($sql) or die (mysql_error());
$data = mysql_fetch_array($result) or die(mysql_error());
$hits = $data['hits'];
$hits = $hits +1;
$sql = "UPDATE ref SET hits = '$hits' WHERE id = '$refid'";
$result = mysql_query($sql) or die (mysql_error());
$hits = 0;
}

//If they IP is already in the database
if ($numrows == 1)
{
$sql = "SELECT * FROM ref WHERE ip = '$clientip'";
$result = mysql_query($sql) or die(mysql_error());
$data = mysql_fetch_array($result) or die(mysql_error());
$id = $data['id'];
$hits = $data['hits'];
}

//Change skin if required
if ($updateskin == 1)
{
$sql = "UPDATE ref SET skinname = '$newskin', skinselect = '1' WHERE id = '$id'";
$result = mysql_query($sql) or die (mysql_error());
}

//Get from database if there has been a skin selected already
$sql = "SELECT * FROM ref WHERE ip = '$clientip'";
$result = mysql_query($sql) or die(mysql_error());
$data = mysql_fetch_array($result) or die(mysql_error());
$skinselect = $data['skinselect'];
$skinname = $data['skinname'];

1 个答案:

答案 0 :(得分:0)

使用:

print_r($_GET);

打印出获取变量的数组。

您提到的错误是关于$ _GET在不存在时的调用。

在尝试使用未设置的内容之前使用isset方法http://uk3.php.net/manual/en/function.isset.php进行检查