I've seen several requests for the ability to have a login/logout auth box on websites that have their website seperate from their store.
This script simply includes the login box, allowing them to login to the store, and shows the logout box when they are already logged in.
It grabs the login variable, so you could expand this further on your pages by doing php mysql queries to do database manipulation with it.
Requirements:
- This is tested to work on 3.5.8 and I'm not sure if it works on any others.
- It assumes that your website pages are in a folder underneath the customer folder
(if it is not you must change the path of the require auth.php line)
- The page you want the box to appear on must parse php
Usage:
- Copy the code below and paste into a file called loginscript.php
- Upload the file to web server
- Open the page you want the box to appear on, and include the loginscript.php
The code will look something like:
Code:
<?
include "/path/to/loginscript.php";
?>
That's it. Here's the code:
Code:
<?
#===========================================================================================#
# #
# X-CART LOGIN INTEGRATION - Jon Peters #
# This script allows you to put a login/logout box on your non-xcart pages #
# The $login variable can be used to pull further information from the database #
# #
# Created July 16, 2004 #
# #
#===========================================================================================#
# #
# USAGE: #
# #
# Edit the style config variables below to match your site look #
# Save this code as loginscript.php and upload to your server #
# Include the file on your php pages (using a php include) where you want the box to appear #
# #
#===========================================================================================#
#---------------------------------------------
# REQUIRE X-CART INFORMATION
#---------------------------------------------
require_once "./customer/auth.php";
#---------------------------------------------
# STYLE VARIABLES (Configure These)
#---------------------------------------------
$bar_backgroundcolor = "#18409A";
$bar_font_face = "Arial";
$bar_font_color = "#FFFFFF";
$bar_font_size = "2";
$text_font_face = "Verdana";
$text_font_color = "#000000";
$text_font_size = "1";
$width = "150";
?>
<?
#---------------------------------------------
# SHOW LOG IN
#---------------------------------------------
if (!$login) {
?>
<table border="0" cellpadding="5" cellspacing="0" width="<?= $width; ?>">
<tr>
<td bgcolor="<?= $bar_backgroundcolor; ?>" height="26" width="100%"><font face="<?= $bar_font_face; ?>" color="<?= $bar_font_color; ?>" size="<?= $bar_font_size; ?>">
Member Login</font></td>
</tr>
<tr>
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<FORM action="/include/login.php" method=post name=authform>
<input type="hidden" name="xid" value="<?= $XCARTSESSID; ?>">
<tr>
<td><font face="<?= $text_font_face; ?>" color="<?= $text_font_color; ?>" size="<?= $text_font_size; ?>">Username</font>
<input type="text" name="username" size="16">
<font face="<?= $text_font_face; ?>" color="<?= $text_font_color; ?>" size="<?= $text_font_size; ?>">Password</font>
<input type="password" name="password" size="16">
<input type="hidden" name="mode" value="login">
<input type="hidden" name="usertype" value="C">
<input type="hidden" name="redirect" value="customer"></td>
</tr>
<tr>
<td height="24">
<a href="javascript: document.authform.submit()">
<font face="<?= $text_font_face; ?>" color="<?= $text_font_color; ?>" size="<?= $text_font_size; ?>">Login </font><input type="image" src="/skin1/images/go_menu.gif" width="27" height="14" border="0" align="absmiddle"></a>
</td>
</tr>
<tr>
<td height="24" align="center">
<font face="<?= $text_font_face; ?>" color="<?= $text_font_color; ?>" size="<?= $text_font_size; ?>">Register</font> <font face="<?= $text_font_face; ?>" color="<?= $text_font_color; ?>" size="<?= $text_font_size; ?>">|</font>
<font face="<?= $text_font_face; ?>" color="<?= $text_font_color; ?>" size="<?= $text_font_size; ?>">Lost Pass?</font></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
<?
#---------------------------------------------
# SHOW LOG OUT
#---------------------------------------------
} else {
?>
<table border="0" cellpadding="5" cellspacing="0" width="<?= $width; ?>">
<tr>
<td bgcolor="<?= $bar_backgroundcolor; ?>" height="26" width="100%"><font face="<?= $bar_font_face; ?>" color="<?= $bar_font_color; ?>" size="<?= $bar_font_size; ?>">
Member Login</font></td>
</tr>
<tr>
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<form action="/include/login.php" method=post name=loginform>
<tr>
<td valign="top">
<font face="<?= $text_font_face; ?>" color="<?= $text_font_color; ?>" size="<?= $text_font_size; ?>">You're logged in as: <?= $login; ?></font>
<font face="<?= $text_font_face; ?>" color="<?= $text_font_color; ?>" size="<?= $text_font_size; ?>">Logoff </font><input type="image" src="/skin1/images/go_menu.gif" border="0" align="absmiddle" width="27" height="14">
</td>
</tr>
<input type="hidden" name="mode" value="logout"><input type="hidden" name="redirect" value="customer">
</form>
</table>
</table>
<?
}
?>