url 重定向的用户名
Username to url redirect
我安装了一个基本系统 table 应该读取用户名和 url 但我是一个完全的菜鸟 PHP 这就是我得到的,如果有人可以帮助我,这样当输入用户名时,它会自动将他们重定向到与该帐户关联的 url 谢谢。
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="redirect"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$myusername = mysql_real_escape_string($myusername);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file"login_success.php"
$_SESSION['username'] = $myusername;
$result = mysql_query("SELECT redirect FROM members");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
header("Location: " . $row['redirect']);
}
exit();
}
else {
echo "Wrong Username or Password";
}
?>
编辑:
快速更新基本上这有一个文本输入框,当填入正确的密码短语时,它会将您重定向到一个外部 url,它与数据库中的名称一起保存。我不知道如何获得它,以便如果有人有关于此 ID 的教程喜欢它,则重定向从文本框正确发生
if(isset($_SESSION['username'])){
header("location: http://yoururl/" .$_SESSION['username']);
}
<?php
if($_POST){
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="redirect"; // Table name
// Connect to server and select databse.
$con = mysqli_connect($host, $username, $password, $db_name);
// username sent from the form
$myusername = $_POST['myusername'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$sql = "SELECT * FROM redirect WHERE username='$myusername' LIMIT 1";
$result = mysqli_query($con, $sql);
// Mysqli_num_row is counting table row
$count = mysqli_num_rows($result);
// If result matched $myusername, table row must be 1 row
if($count === 1){
$_SESSION['username'] = $myusername;
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
//redirect to file url from database
header("Location: " . $row['url']);
}else{
echo 'Invalid Username';
}
}else{
?>
<html lang="en">
<head>
<title>My App</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="text" name="myusername"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
<?php } ?>
这应该可以解决...
用你的替换这个。
$result = mysql_query("SELECT redirect FROM members where username = '.$myusername.'");
我安装了一个基本系统 table 应该读取用户名和 url 但我是一个完全的菜鸟 PHP 这就是我得到的,如果有人可以帮助我,这样当输入用户名时,它会自动将他们重定向到与该帐户关联的 url 谢谢。
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="redirect"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$myusername = mysql_real_escape_string($myusername);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file"login_success.php"
$_SESSION['username'] = $myusername;
$result = mysql_query("SELECT redirect FROM members");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
header("Location: " . $row['redirect']);
}
exit();
}
else {
echo "Wrong Username or Password";
}
?>
编辑: 快速更新基本上这有一个文本输入框,当填入正确的密码短语时,它会将您重定向到一个外部 url,它与数据库中的名称一起保存。我不知道如何获得它,以便如果有人有关于此 ID 的教程喜欢它,则重定向从文本框正确发生
if(isset($_SESSION['username'])){
header("location: http://yoururl/" .$_SESSION['username']);
}
<?php
if($_POST){
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="redirect"; // Table name
// Connect to server and select databse.
$con = mysqli_connect($host, $username, $password, $db_name);
// username sent from the form
$myusername = $_POST['myusername'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$sql = "SELECT * FROM redirect WHERE username='$myusername' LIMIT 1";
$result = mysqli_query($con, $sql);
// Mysqli_num_row is counting table row
$count = mysqli_num_rows($result);
// If result matched $myusername, table row must be 1 row
if($count === 1){
$_SESSION['username'] = $myusername;
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
//redirect to file url from database
header("Location: " . $row['url']);
}else{
echo 'Invalid Username';
}
}else{
?>
<html lang="en">
<head>
<title>My App</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="text" name="myusername"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
<?php } ?>
这应该可以解决...
用你的替换这个。
$result = mysql_query("SELECT redirect FROM members where username = '.$myusername.'");