Forums

PHP

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> &lt;% if Session("MM_Username" &lt;&gt; "" then %&gt;

Welcome &lt;%= Session("MM_Username" %&gt;&lt;br&gt;
&lt;A HREF="&lt;%= MM_Logout %&gt;"&gt;Log Out&lt;/A&gt;

&lt;%End If %&gt;

&lt;% if Session("MM_Username" = "" then %&gt;

&lt;form name="form1" method="post" action="&lt;%=MM_LoginAction%&gt;"&gt;
&lt;table width="150" border="0" cellspacing="0" cellpadding="3"&gt;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;Name:&lt;/b&gt;
&lt;input type="text" name="txtName"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;Password:&lt;/b&gt;
&lt;input type="password" name="txtPassw"&gt;
&lt;br&gt;
&lt;font size="2"&gt;
&lt;input type="checkbox" name="checkbox" checked&gt;
remember me&lt;br&gt;&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="center"&gt;
&lt;input type="submit" name="Submit" value="log in &gt;&gt;"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;%End If %&gt;</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 &lt;body&gt;
Add this anywhere you want.
Welcome &lt;?=$username?&gt;
</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();

Reply to this topic