Jump to content

Archived

This topic is now archived and is closed to further replies.

Deon

PHP & Login Sessions

Recommended Posts

Hi there,

DW 8.0.2, PHP & mySQL

I use this in my ASP VBScript pages which I got from a NG.

[i] [b]<% if Session("MM_Username") <> "" then %>[/b]

<Strong>Welcome <%= Session("MM_Username") %>< /strong><br>
<A HREF="<%= MM_Logout %>">Log Out</A>

[b]<%End If %>[/b]

[b]<% if Session("MM_Username") = "" then %>[/b]

<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 &gt;&gt;">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>

[b] <%End If %>[/b]
[/i]

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

Share this post


Link to post
Share on other sites
Perhaps something like:

[code]<?php if ($_SESSION['MM_Username'] != "") { ?>

<Strong>Welcome <?= $_SESSION['MM_Username'] ?>< /strong><br>
<A HREF="<?= $MM_Logout ?>">Log Out</A>

<?php } else {  ?>

<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 &gt;&gt;">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>

<?php } ?>[/code]

Share this post


Link to post
Share on other sites
Thank you so much!!! This is exactly 100% what I needed.

Why do I get this message?

Notice: Undefined index: MM_Username in c:\Inetpub\wwwroot\sincro\members\member-login.php on line 277

when not logged in? Apart from this message, your suggestions work 100% and perfectly well.

This is line 277:
<?php if ($_SESSION['MM_Username'] != "") { ?>

Regards,
Deon

Share this post


Link to post
Share on other sites
This happens because $_SESSION['MM_Username'] is not defined.

If you defined it indeed, maybe the session is not being passed correctly.

Share this post


Link to post
Share on other sites
I noticed that you are using a windows server, please note I have found a lot of severe issues regarding the use of php with IIS

Share this post


Link to post
Share on other sites
Thank you so much to the both of you.

I have uploaded my test files to my server and it works perfectly well. Maybe there is something wrong with the settings/installation of PHP on my testing PC.

Thank you again!

Regards,
Deon

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.