我有一个域,其中用户有一个具有自己名称的子域。
例子:
- 用户:维托
- 子域:vitor.google.com
该数据库具有user
列表,my_users
并具有列birthday
、address
、和in 表。我如何在 PHP 中做到这一点,才能将这些信息直接用户访问数据库?password
city
state
users_infos
index.php
这是我的错误代码:
// Get Subdomain
$urlExplode = explode('.', $_SERVER['HTTP_HOST']);
if (count($urlExplode) > 2 && $urlExplode[0] !== 'www') {
$subdomain = $urlExplode[0];
echo $subdomain;
}
// Select DB
$sql = "SELECT * FROM users_infos i INNER JOIN my_users u on u.id = i.id where u.users='$users'";
$result = mysql_query($sql);
if($result === FALSE) {
die(mysql_error());
// TODO: better error handling
}
else {
$row = mysql_fetch_array($result);
$userTitleSite = $row['userTitleSite'];
echo $id_textos = $row["id_textos"];
echo "<br />";
echo $id = $row["id"];
echo "<br />";
echo $phone = $row["phone"];
echo "<br />";
echo "<br />";
}
// Says that the subdomain is = user
$subdomain = $user;
正确答案如下:
使用您给我的帮助,看起来我到了这里.. 遵循我可以为有相同问题的未来用户执行的正确代码:
// Get subdomain
$urlExplode = explode('.', $_SERVER['HTTP_HOST']);
if (count($urlExplode) > 2 && $urlExplode[0] !== 'www') {
$subdomain = $urlExplode[0];
echo $subdomain;
}
// Says that the subdomain is = user
$user = $subdomain;
// Select DB
$sql = "SELECT * FROM vms_textos i INNER JOIN vms_users u on u.id = i.id where u.user='$user'";
$result = mysql_query($sql);
if($result === FALSE) {
die(mysql_error());
// TODO: better error handling
}
else {
$row = mysql_fetch_array($result);
$userTitleSite = $row['userTitleSite'];
echo "<br />";
echo $id_textos = $row["id_textos"];
echo "<br />";
echo $user= $row["user"];
echo "<br />";
echo $id = $row["id"];
echo "<br />";
echo $telefone = $row["telefone"];
echo "<br />";
echo "<br />";
}
echo "<br />";
echo "<br />";
谢谢大家帮助我!:)