本文介绍了我的IP是否在我的数据库中,如果是,请查找时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我想知道这个:

OK, so I want to know this:

我的数据库中有我的IP吗?如果是,请找到条目的时间戳。

Is my IP in my database? If yes, find the timestamp of entry.

到目前为止我有这个:

$ip = $_SERVER['REMOTE_ADDR'];
$myip = mysql_query("SELECT * FROM votes WHERE ip = '$ip'");

If(mysql_num_rows($myip) > 0){
//find timestamp and name it as a variable e.g $ipTime

就我而言,就我而言,我有点陷入困境,有人帮助过我吗?

Thats as far as I've got, and for the life of me, I'm a little stuck, anyone help me?

推荐答案

这应该可以解决问题,它应该获取时间戳并将其转换为人类可读格式,您可能还需要查找PHP date()根据自己的喜好调整 $ date_format 的函数,可以在这里找到:

This should do the trick, it should get the timestamp and convert it to a human readable format, you may also want to look up the PHP date() function to adjust the $date_format to your liking which can be found here: http://php.net/manual/en/function.date.php

$ip = $_SERVER['REMOTE_ADDR']; // Fetch IP

$query = mysql_query("SELECT `timestamp` FROM `votes` WHERE (`ip` = '$ip')") or die(mysql_error()); // Queries IP

$amount = mysql_num_rows($query); // Amount of times listed (rows)

if ($amount > 0) { // If exists

    $row = mysql_fetch_array($query);

    $timestamp = $row['timestamp'];

    $date_format = 'm F \a\t g:ia';
    $date = date("$date_format", $timestamp); // Converts timestamp

    echo("Your IP Address (".$ip.") is already listed at ".$date."");

} else {

    echo("Your IP Address is not currently listed");

}

这篇关于我的IP是否在我的数据库中,如果是,请查找时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 07:18