Frontend loging in phpwcms
Posted: Wed 8. Sep 2004, 11:24
Since it seems to me that it takes ages to wait for frontend logging in phpwcms, I did it by myself, it is working and I hope this helps developers also to relase properly coded frontend logging
So lets get to the point.
1) modify index.php
uncomment on line 34
2) make new php file and name it authorize.php and add following code in it. (ps this code is borrowed from login.php
)
Then I made a custom form and named it frm_Login.php (also borrowed from login.php, just removed things I fought I don't need:? )
also I added some lines into include\inc_conf\conf.template_default.inc.php
and now the critical part !!!
I had to change include\inc_front\content_func.inc.php
Find out code like
and add there code which is cheking from site structure frontend menu status: is this visible for users logged on only.
now there is a small shortage: when you are'nt logged in meny does not show this item. So basically you have to add manually some link to some yours private page.
well I hope this helped someone![Confused :?](./images/smilies/icon_confused.gif)
![Wink :wink:](./images/smilies/icon_wink.gif)
So lets get to the point.
1) modify index.php
uncomment on line 34
Code: Select all
session_start();
![Embarassed :oops:](./images/smilies/icon_redface.gif)
Code: Select all
<?php
if(isset($_POST['form_aktion']) && $_POST['form_aktion'] == 'login') {
$login_passed = 0;
$wcs_user = slweg(trim($_POST['form_loginname']));
$wcs_pass = slweg(trim($_POST['form_password']));
$sql_query = "SELECT * FROM ".DB_PREPEND."phpwcms_user WHERE usr_login='".
aporeplace($wcs_user)."' AND (usr_pass=PASSWORD('".
aporeplace($wcs_pass)."') OR usr_pass='".
aporeplace(md5($wcs_pass))."') AND usr_aktiv=1;";
if($result = mysql_query($sql_query)) {
if($row = mysql_fetch_array($result)) {
$_SESSION["wcs_user"] = $wcs_user;
$_SESSION["wcs_pass"] = $wcs_pass;
$_SESSION["wcs_user_name"] = ($row["usr_name"]) ? $row["usr_name"] : $wcs_user;
$_SESSION["wcs_user_id"] = $row["usr_id"];
$_SESSION["wcs_user_aktiv"] = $row["usr_aktiv"];
$_SESSION["wcs_user_rechte"] = $row["usr_rechte"];
$_SESSION["wcs_user_email"] = $row["usr_email"];
$_SESSION["wcs_user_avatar"] = $row["usr_avatar"];
$_SESSION["wcs_user_logtime"] = time();
$_SESSION["wcs_user_admin"] = $row["usr_admin"];
$_SESSION["wcs_user_thumb"] = 1;
if($row["usr_lang"]) {
$_SESSION["wcs_user_lang"] = $row["usr_lang"];
}
$_SESSION["structure"] = unserialize($row["usr_var_structure"]);
$_SESSION["klapp"] = unserialize($row["usr_var_privatefile"]);
$_SESSION["pklapp"] = unserialize($row["usr_var_publicfile"]);
$login_passed = 1;
$_SESSION["frontend_user_in"]=true; //changed this one
}
mysql_free_result($result);
}
}
?>
Then I made a custom form and named it frm_Login.php (also borrowed from login.php, just removed things I fought I don't need:? )
Code: Select all
<table border="0" cellpadding="0" cellspacing="0">
<form name="login_formular" method="post" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'] ?>" autocomplete="off">
<tr><td width="389" class="title"><?php echo $GLOBALS["template_default"]["login_text"]; ?></td></tr>
<?php
if($err) {
echo '<tr><td><img src="img/leer.gif" width="1" height="10"></td></tr>';
echo '<tr><td class="error"><strong>'.$GLOBALS["template_default"]["login_error"].'</strong></td></tr>';
}
?>
<tr><td><img src="img/leer.gif" width="1" height="12"></td></tr>
<tr><td class="v10"><?php echo $GLOBALS["template_default"]["login_username"] ?>:</td></tr>
<tr><td><input name="form_loginname" type="text" id="form_loginname" class="f11b" style="width:250px;" size="30" maxlength="30" value="<?php echo html_specialchars($wcs_user); ?>"></td></tr>
<tr><td><img src="img/leer.gif" width="1" height="3"></td></tr>
<tr><td class="v10"><?php echo $GLOBALS["template_default"]["login_userpass"] ?>:</td></tr>
<tr><td><input name="form_password" type="password" id="form_password" class="f11b" style="width:250px;" size="30" maxlength="20"></td></tr>
<tr><td><img src="img/leer.gif" width="1" height="3"></td></tr>
<tr><td><img src="img/leer.gif" width="1" height="18"></td></tr>
<tr><td><input name="Submit" type="submit" class="button10" value="<?php echo $GLOBALS["template_default"]["login_button"] ?>"><input name="form_aktion" type="hidden" id="form_aktion" value="login"></td></tr>
</form>
</table>
Code: Select all
// login form template
$template_default["login_text"] = "Please Log in";
$template_default["login_error"] ="Wrong password";
$template_default["login_username"] ="Username";
$template_default["login_userpass"] ="Password";
$template_default["login_button"] ="Login";
I had to change include\inc_front\content_func.inc.php
Find out code like
Code: Select all
$content["all"] = str_replace('{CONTENT}', $content["main"], $content["all"]);
Code: Select all
$cat=$content["cat_id"];
if($content["struct"][$cat]["acat_regonly"]==1)
{
//echo "Private area!!!";
include_once("authorize.php");
if(!$_SESSION["frontend_user_in"]) {
//show log in form, instead of page content";
$content["main"]="{PHP:frm_Login.php}";
}
}
$content["all"] = str_replace('{CONTENT}', $content["main"], $content["all"]);
well I hope this helped someone
![Confused :?](./images/smilies/icon_confused.gif)