I am trying to set cookies in two different scenarios: - When users sign up.
- When users login.
and then they will be directed to main.php where main.php includes header.php. Now all the problem is with header.php when users login they are redirected to main.php where header menu should be home, profile, logout etc but when users who are not logged in visit main.php. header menus should be sign up and login.
register.php - <?php
-
$con = mysqli_connect("localhost","root","","findfriends") or die ("Connection not established");
-
?>
-
<?php include ( "./inc/header.inc.php" ); ?>
-
<?php
-
-
if(isset($_POST['reg'])){
-
$fn=strip_tags(@$_POST['fname']);
-
$ln=strip_tags(@$_POST['lname']);
-
$un=strip_tags(@$_POST['username']);
-
$em=strip_tags(@$_POST['email']);
-
$pswd=strip_tags(@$_POST['password']);
-
$d= date("Y-m-d");
-
-
$reg_query = "INSERT INTO users (userid,username,first_name,last_name,email,password,sign_up_date,activated,bio,profile_photo,closed) VALUES ('','{$un}','{$fn}','{$ln}','{$em}','{$pswd}','{$d}','0','What you do?','','no')";
-
$reg_run = mysqli_query($con,$reg_query);
-
setcookie('user',$uname,time()+3600*24*365);
-
echo "The cookie has been set.";
-
-
header("Location:main.php");
-
-
}
-
?>
-
-
<?php
-
if(isset($_POST['login'])){
-
$log_que = "SELECT * FROM users WHERE username = '$un' AND password = '$pswd' ";
-
$log_run = mysqli_query($con, $log_que);
-
$row = mysql_fetch_array($log_run);
-
$un_db = $log_row['username'];
-
$pswd_db = $log_row['password'];
-
-
if($un == $un_db && $pswd == $pswd_db)
-
{
-
echo "LOGGED IN!";
-
setcookie('user',$uname,time()+3600*24*365);
-
header("Location:main.php");
-
}
-
}
-
?>
-
-
<div style="width: 800px; margin: 0px auto 0px auto;">
-
<table>
-
<tr>
-
<td width="60%" valign="top">
-
<h2>Already a member? Login Below</h2>
-
<form action="" method="POST">
-
<input type="text" name="user_login" size="25" placeholder="UserName"/><br><br>
-
<input type="password" name="password_login" size="30" placeholder="Passsword"/><br><br>
-
<input type="submit" name="login" value="Login">
-
</form>
-
</td>
-
<td width="40%" valign="top">
-
<h2>Sign Up!</h2>
-
<form action="" method="POST">
-
<input type="text" name="fname" size="25" placeholder="First Name"/><br><br>
-
<input type="text" name="lname" size="25" placeholder="Last Name"/><br><br>
-
<input type="text" name="username" size="25" placeholder="Username"/><br><br>
-
<input type="email" name="email" size="25" placeholder="Email"/><br><br>
-
<input type="password" name="password" size="25" placeholder="Password"/><br><br>
-
<input type="submit" name="reg" value="Sign Up!">
-
</form>
-
</td>
-
</tr>
-
</table>
header.php - <!DOCTYPE html>
-
<html>
-
<head>
-
<title>findfriends</title>
-
<script src="js/main.js" type="text/javascript"></script>
-
<link rel="stylesheet" type="text/css" href="./css/style.css"/>
-
-
</head>
-
<body>
-
-
<div class="headerMenu">
-
<div id="wrapper">
-
<div class="logo">
-
<img src="./img/logo.gif"/>
-
</div>
-
<div class="search_box">
-
<form action="searchresults.php" method="post" name="search">
-
<table>
-
<tr>
-
<td>
-
<input type="text" name="search" placeholder="Search ..."/>
-
</td>
-
<td>
-
<input type="image" src="./img/search-icon.png" alt="submit" />
-
</td>
-
</tr>
-
</table>
-
</form>
-
</div>
-
-
<div class="cb">
-
<a href="create_blog.php">Create a Blog</a>
-
</div>
-
-
-
<?php
-
if(isset($_COOKIE['user'])){
-
echo '
-
-
<ul class="dd">
-
-
<li><a href="main.php" >Home</a></li>
-
<li><a href="' . $user . '">Profile</a></li>
-
<li><a href="my_messages.php">Inbox' . $unread_numrows . '</a></li>
-
<li><a href="#">Management</a>
-
<ul><li><a href="account_settings.php">Settings</a></li>
-
<li><a href="logout.php">Logout</a></li>
-
</ul>
-
</li>
-
</ul>';
-
-
}
-
else
-
{
-
echo '
-
<ul class="dd">
-
<li><a href="register.php" >Sign Up</a></li>
-
-
<li><a href="register.php">Login</a></li>
-
</ul>';
-
}
-
?>
-
-
-
</div>
-
</div>
-
</body>
-
</html>
main.php is empty with just with hello world to test header working.
0 1012 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ian Sedwell |
last post by:
Hi guys
I've come across a problem with cookies. It seems that if one attempts to
save several cookies in quick succession and then read them back again, you
may attempt to read a cookie that has not yet been saved from the first
operation. I assume that this is because JavaScript via the browser hands
the job over to the OS and then...
|
by: zoltix |
last post by:
Hi,
I would like to access to execute specific commands but the privileges
are not enough from an aspx Page. Because this service run as
IU_IISSERVER, therefore aspx hasn’t access to these resources and it is
normal.. But sometimes, I need these privileges for special commands.
How to execute some “lines code” for other user than currently...
|
by: David Lozzi |
last post by:
Howdy,
I have a user control that is a report to display data. On the page the
control is inserted in, I have filter options to filter the report. When I
try to do something like this, nothing happens.
dim filt as string
... build filter string...
UserControl.ReportFilter = filt
|
by: Greg |
last post by:
Please note: I have cross posted this from Newsgroup:
microsoft.public.dotnet.framework.aspnet.webservices
with a few minor changes...
I am having a simple problem setting up the security on my test web
service...
My Web service code is:
Imports System.Web.Services
|
by: Patxi |
last post by:
This is the first time I try to use cookies, and despite of reading some
tutotials, I'm have real trouble to make it work correctly. My cookie
reading code is in Master Page. When I click on a test button (in a WEb
User Control inside the aspx page), cookie value is displayed in Master
Page but if I go to another page, no value is...
| |
by: mvr |
last post by:
Hi all
How to get the Windows current logged user name using Classic ASP.
If no direct way are there any work arounds.
Thanks
mvr
|
by: Greg Hurlman |
last post by:
I have an HttpModule that captures the
FormsAuthenticationModule.Authenticate event, and replaces the
HttpContext principal with a custom principal. The code is
straightforward enough, yet when an ASPX page tries to get this custom
principal it fails - the object I inserted is not there. I've tried
having this module declaration at both the...
|
by: Vlad Dogaru |
last post by:
Hello,
I am trying to use cookies and Python to create a simple login example.
But I am very disoriented at the existence of two cookie libraries,
namely Cookie and cookielib. I have seen examples of setting cookies
(although I am still not sure about timestamps and cookie lifespan),
but no reference to getting the currently set cookies....
|
by: Shwan |
last post by:
Dear developers,
I working on C# .NET, I have a problem how to prevent a user to login in to the system while another one already logged in using the Same User Name And Password. I tried to put a Flag in the Users Table but to reset the Flag I have to be sure that the user should Sing out and not close the system immediately, So please if you...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |