假设我有一个名为“ user.php”的页面。 我希望登录的用户只能访问
user.php?user =用户名。
如果有人在浏览器中输入user.php,我不希望他们看到显示不带url扩展名的user.php的常规页面。有小费吗?谢谢
答案 0 :(得分:3)
您可以使用$ _SESSION
用户登录后添加
#Main
import random
player_rps = input('Rock, Paper, Scissors, Lizard, or Spock:\t').upper()
computer_rps = ['ROCK','PAPER','SCISSORS','SPOCK','LIZARD']
game_rps = random.choice(computer_rps)
#Player
if player_rps == 'ROCK':
print('Player picked Rock')
elif player_rps == 'PAPER':
print('Player picked Paper')
elif player_rps == 'SCISSORS':
print('Player picked Scissors')
elif player_rps == 'SPOCK':
print('Player picked Spock')
elif player_rps == 'LIZARD':
print('Player picked Lizard')
#Computer
if game_rps == 'ROCK':
print('Computer picked Rock')
elif game_rps == 'PAPER':
print('Computer picked Paper')
elif game_rps == 'SCISSORS':
print('Computer picked Scissors')
elif game_rps == 'SPOCK':
print('Computer picked Spock')
elif game_rps == 'LIZARD':
print('Computer picked Lizard')
#Output for rock
if player_rps == "ROCK" and game_rps == "SCISSORS":
print("Rock crushes scissors, the Player wins!")
if player_rps == "SCISSORS" and game_rps == "ROCK":
print("Rock crushes scissors, the Computer wins!")
if player_rps == "ROCK" and game_rps == "PAPER":
print("Paper covers rock, the Computer wins!")
if player_rps == "PAPER" and game_rps == "ROCK":
print("Paper covers rock, the Player wins!")
if player_rps == "ROCK" and game_rps == "SPOCK":
print("Spock vaporizes rock, the Computer wins!")
if player_rps == "SPOCK" and game_rps == "ROCK":
print("Spock vaporizes rock, the Player wins!")
if player_rps == "ROCK" and game_rps == "LIZARD":
print("Rock crushes lizard, the Player wins!")
if player_rps == "LIZARD" and game_rps == "ROCK":
print("Rock crushes lizard, the Computer wins!")
#Output for paper
if player_rps == "PAPER" and game_rps == "LIZARD":
print("Lizard eats paper, the Computer wins!")
if player_rps == "LIZARD" and game_rps == "PAPER":
print("Lizard eats paper, the Player wins!")
if player_rps == "PAPER" and game_rps == "SCISSORS":
print("Scissors cuts paper, the Computer wins!")
if player_rps == "SCISSORS" and game_rps == "PAPER":
print("Scissors cuts paper, the Player wins!")
if player_rps == "PAPER" and game_rps == "SPOCK":
print("Paper disproves spock, the Player wins!")
if player_rps == "SPOCK" and game_rps == "PAPER":
print("Paper disproves spock, the Computer wins!")
#Output for scissors
if player_rps == "SCISSORS" and game_rps == "SPOCK":
print("Spock smashes scissors, the Computer wins!")
if player_rps == "SPOCK" and game_rps == "SCISSORS":
print("Spock smashes scissors, the Computer wins!")
if player_rps == "SCISSORS" and game_rps == "LIZARD":
print("Scissors decapitates lizard, the Player wins!")
if player_rps == "LIZARD" and game_rps == "SCISSORS":
print("Scissors decapitates lizard, the Computer wins!")
#Output for spock
if player_rps == "SPOCK" and game_rps == "LIZARD":
print("Lizard poisons spock, the Computer wins!")
if player_rps == "LIZARD" and game_rps == "SPOCK":
print("Lizard poisons spock, the Player wins!")
if player_rps == game_rps:
print("It's a tie!")
else:
print("Please enter the correct option: Rock, Paper, Scissors, Spock,
Lizard")
并在用户页面顶部添加
$_SESSION['logedin'] = '1';
也不要忘记在登录页面和用户页面上启动或恢复会话
if ( $_SESSION['logedin'] !== '1' ) {
echo "Please Login to continue";
die();
}
答案 1 :(得分:2)
用户登录时,应将用户存储在会话中。 如果用户存在于会话中,则在“ user.php”页面上可以具有一个功能 然后让他进入,如果不存在,只需重定向他。
用户登录后设置会话
$_SESSION['logged'] = 'YouCanPutUsersNameHere';
在要用户登录的每个页面上使用此功能。
function checkLogin() {
if (!isset($_SESSION['logged'])) {
header("location: /login");
exit;
}
}