Forums
This topic is locked
PHP & Sessions
Posted 27 May 2006 20:26:23
1
has voted
27 May 2006 20:26:23 Deon Holtzhausen posted:
Hi there,DW 8.0.2, PHP & mySQL
I use this in my ASP VBScript pages which I got from a NG.
<pre id=code><font face=courier size=2 id=code> <% if Session("MM_Username" <> "" then %>
Welcome <%= Session("MM_Username" %><br>
<A HREF="<%= MM_Logout %>">Log Out</A>
<%End If %>
<% if Session("MM_Username" = "" then %>
<form name="form1" method="post" action="<%=MM_LoginAction%>">
<table width="150" border="0" cellspacing="0" cellpadding="3">
<tr>
<td><b>Name:</b>
<input type="text" name="txtName">
</td>
</tr>
<tr>
<td><b>Password:</b>
<input type="password" name="txtPassw">
<br>
<font size="2">
<input type="checkbox" name="checkbox" checked>
remember me<br></font></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="Submit" value="log in >>">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<%End If %></font id=code></pre id=code>
This works perfectly well for me. What it does is to welcome a visitor with his/her registrated name once logged in together with a Log out link. The log out is done with DW.
If the visitor is NOT logged in, it presents the visitor with the login form.
How can I accomplich the same with PHP? I will REALLY appreciate your help.
Regards,
Deon
Everyone of us is a pencil in the hand of a Loving God with which He writes Love Letters to the worlds.
~ Mother Teresa ~
Replies
Replied 29 May 2006 17:21:44
29 May 2006 17:21:44 Roddy Dairion replied:
on your login page in php. You need to define what you will use a session so it will look something like this
<pre id=code><font face=courier size=2 id=code>
on top of page
session_start();
$_SESSION['user_id'] = "variable that you will use to identify user";
$_SESSION['username'] = "variable that you will use for username";
then on everypage you need something like this
session_start();
if (isset($_SESSION['user_id']))
{
$username = $_SESSION['username'];
}
else
{
header("location: yourloginpage.php"
}
within your <body>
Add this anywhere you want.
Welcome <?=$username?>
</font id=code></pre id=code>
It won't be just the code posted above but you will need somemore. But these are the basics.
on each page if you're checking session you need to start your page with session_start();
<pre id=code><font face=courier size=2 id=code>
on top of page
session_start();
$_SESSION['user_id'] = "variable that you will use to identify user";
$_SESSION['username'] = "variable that you will use for username";
then on everypage you need something like this
session_start();
if (isset($_SESSION['user_id']))
{
$username = $_SESSION['username'];
}
else
{
header("location: yourloginpage.php"
}
within your <body>
Add this anywhere you want.
Welcome <?=$username?>
</font id=code></pre id=code>
It won't be just the code posted above but you will need somemore. But these are the basics.
on each page if you're checking session you need to start your page with session_start();