我正在制作联盟计划,我根据此链接计算了一些点击次数iceblasteraffiliate.freeiz.com/affiliate/?numberherebasedonid但是我有这个
<?php
$conn = mysqli_connect("redacted", "redacted", "redacted",
"redacted");
if (!$conn) {
die("Connection failed: ".mysqli_connect_error());
}
session_start();
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$sql = "SELECT clicks FROM affiliate WHERE ID='$ID'";
$add = 1;
$ID = strpos($url, needle)
?>
但正如您所见,我无法弄清楚如何拨打网址中的号码来计算点击次数
答案 0 :(得分:1)
您想要使用GET变量。请尝试以下网址:
fridgeblasteraffiliate.freeiz.com/affiliate/?id=numberherebasedonid
然后在脚本中使用$_GET['id']
来访问该值。
$sql = "SELECT clicks FROM affiliate WHERE ID='$_GET['id']'";
请注意,此代码为vulnerable to SQL injection.正如Magnus Eriksson在评论中指出的那样,您可以通过将$_GET['id']
类型转换为int类型或使用预准备语句来否定这一点:
铸造:
$id = (int)$_GET['id'];
$sql = "SELECT clicks FROM affiliate WHERE ID='$id'";
准备好的陈述:
$statement = $conn->prepare('SELECT clicks FROM affiliate WHERE ID=?');
$statement->bind_param('s', $_GET['id']);
$statement->execute();