这是我的第一篇文章,所以请对评论进行温和处理。检查用户是否已登录,然后检查用户是否使用单选按钮进行了登录
我有一个网站我正在玩。它有一个基本的登录页面/注册页面。如果用户没有登录,他可以访问所有页面,但无法看到价格。当用户登录价格变得可用时。我的问题是我如何做到这一点,当用户在登录页面上时,他有一个选项可以选择两个单选按钮中的一个,并且选定的用户将被登录,并且将显示特定于任一单选按钮的内容。 。即:登录和高价格点击(一旦登录,我可以看到价格高)注销,点击登录与低价格检查,然后我看到只有低价格。
这里是我的login.php
<?php
require('db.php');
// If form submitted, insert values into the database.
if (isset($_POST['username'])){
$username = stripslashes($_REQUEST['username']); // removes backslashes
$username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
//Checking is user existing in the database or not
$query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'";
$result = mysqli_query($con,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if($rows==1){
$_SESSION['username'] = $username;
header("Location: index.php"); // Redirect user to index.php
}else{
echo "<div class='form'><h3>Username/password is incorrect.</h3><br/>Click here to <a href='login_page.php'>Login</a></div>";
}
}else{?>
<!-- header ends here -->
<!-- ****************************************** -->
<!-- enquiry/newsletter/login/register goes here -->
<div class="container">
</div>
<div class="clear"></div>
<!-- Main page content goes here -->
<div class="content_landing">
<p><div class="form">
<h2>Log In to view Prices and Specials</h2>
<form action="" method="post" name="login">
<input type="radio" name="radio" value="birthday" checked> Birthday Prices<br>
<input type="radio" name="radio" value="corporate"> Corporate Prices<br>
<input type="text" name="username" placeholder="Username" required /><br>
<input type="password" name="password" placeholder="Password" required /><br>
<input name="submit" type="submit" value="Login" />
</form>
<p>Not registered yet? <a href='registration.php'>Register Here</a></p>
</div></p>
<?php } ?>
</div>
</div>
代码,一旦用户登录,他看到这个内容(在products.php:(他应该去吧)
<p><b>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
<?php if(isset($_SESSION['username'])){ ?>
<p>Pricing below:</p>
<p><a class="link" href="logout.php" style="text-decoration:none">Logout</a></p>
<?php }else{ ?>
<a class="link" href="login_page.php" style="text-decoration:none">login</a> or <a class="link" href="registration_page.php" style="text-decoration:none">Register</a>
<?php } ?>
我仍然是一个网页设计的超级noobo,所以请原谅我的缩进和方法等
@verjas我基本上希望用户无论登录查看企业或生日聚会价格或如果他们没有登录只是为了查看网页内容。一旦他们登录产品页面将显示企业价格或生日价格。我没有使用数据库来存储价格......他们在每个产品说明下的产品页面的ifset中。 –
是的,那很好,那么我所展示的你将会工作。 – Rasclatt
如果您希望他们只需点击一个按钮,就可以创建单独的表单,只需提交这两个选项即可设置视图类型。 – Rasclatt