Personalized Login for WordPress + aMember

This article does not cover WordPress / aMember integration, which must be complete before the personalized login will work.

First, you’ll need to insert

<?php session_start();?>

into your theme. (Though many times placing this at the end of your header.php file works fine, you may experience a session error with this placement, as WordPress has started its own session.)

UPDATE: To avoid session errors, place the <?php session_start();?> on the very first line of your index.php file, as well as any other main template files –such as archive.php, category.php, page.php, single.php, etc.

Use the following code in your sidebar to display a log in form and register link to users who are not logged in, and a personal greeting to users who are logged in.

<?php if ($au=$_SESSION['_amember_user']){ // user is logged-in
print “Hello $au[name_f] $au[name_l]!
<a href=’/amember/logout.php’>Logout</a>”;
} else { // user is not logged-in
print “<form method=post action=’/amember/login.php’ />
<p>Username: <input type=text name=amember_login size=10></p>
<p>Password: <input type=password name=amember_pass size=10></p>
<p><input type=’submit’ value=’Login’></p>
<p><font color=#F25C21>Not a member yet?</font><a href=’http://YOUR-SITE.com/amember/signup.php’>Signup</a></p>
“; } ?>

Be sure to change ‘YOUR-SITE.com’ to your actual site URL

If you use widgets, paste the code into a PHP widget (like Samsarin PHP Widget) and place as desired. Don’t forget to change YOUR-SITE.com to your actual site URL, making sure the path to amember is correct.

Using the same code as above, let’s add a few CSS style classes for styling your new login form and you’re ready to go. The form above was created with the following code and CSS. Place the code within your sidebar file.

<?php if ($au=$_SESSION['_amember_user']){ // user is logged-in
print “<p class=’signin’>Hello $au[name_f] $au[name_l]!
<a href=’/amember/logout.php’>Logout</a></p>”;
} else { // user is not logged-in
print “<div class=’signinb’>
<form method=post action=’/amember/login.php’ />
<p>Username: <input type=text name=amember_login size=10></p>
<p>Password: <input type=password name=amember_pass size=10></p>
<p><input type=submit <class=’login’ value=’Login’></p>
</div>
<p>Not a member yet?
<a href=’http://YOUR-SITE.com/amember/signup.php’>Signup</a></p>
“; } ?>

CSS –this goes in your style.css file

.signin { color:#333333; font-size:1.1em; width:160px;}
.signin a { color:#4D7587;}
.signin a:hover { color:#03ABDB;}
.signinb { color:#333333; width:160px;}
.signinb a { color:#4D7587;}
.signinb a:hover { color:#03ABDB;}
input.login { margin: 2px 0 4px 0; width: 160px; font-size: 10px; font-family: arial, sans-serif; border: 0; color: #666; padding: 3px; font-weight: bold; border:1px solid #bbb;}

Play around with the code and styles until you’re happy with the style, colors and ‘logged-in’ message.