Using CMSBuilding Login
25 posts by 9 authors in: Forums > CMS Builder
Last Post: October 8, 2009 (RSS)
Re: [andycal] Using CMSBuilding Login
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /var/www/vhosts/horroruk.com/httpdocs/films.php:5) in /var/www/vhosts/horroruk.com/httpdocs/admin/lib/init.php on line 63
Re: [Moonworks] Using CMSBuilding Login
By Chris - September 2, 2009
Your script can't output anything before it tries to start a session. Even a single space before your <?php will cause that error.
If you're not able to get this sorted out yourself, please post your PHP source code (films.php?) as an attachment.
Chris
Re: [chris] Using CMSBuilding Login
Here is the code I have:
<html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<?php
if (!defined('START_SESSION')) { define('START_SESSION', true); }
require_once "/var/www/vhosts/horroruk.com/httpdocs/admin/lib/viewer_functions.php";
if (!@$_SESSION['username']) { die("You must login first!"); }
list($filmRecords, $filmMetaData) = getRecords(array(
'tableName' => 'film',
'perPage' => '10',
));
?>
<title>Horror UK</title>
Re: [Moonworks] Using CMSBuilding Login
By Chris - September 2, 2009
Try this:
<?php
if (!defined('START_SESSION')) { define('START_SESSION', true); }
require_once "/var/www/vhosts/horroruk.com/httpdocs/admin/lib/viewer_functions.php";
if (!@$_SESSION['username']) { die("You must login first!"); }
list($filmRecords, $filmMetaData) = getRecords(array(
'tableName' => 'film',
'perPage' => '10',
));
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<title>Horror UK</title>
Chris
Re: [chris] Using CMSBuilding Login
That worked fine, but just one more question. where it says you must login first, is there a way to being up the login screen?
Re: [Moonworks] Using CMSBuilding Login
By Chris - September 2, 2009
Yes, certainly. Replace the following line:
if (!@$_SESSION['username']) { die("You must login first!"); }
with this one:
if (!@$_SESSION['username']) { header("Location: http://mydomain.com/cmsAdmin/"); exit; }
and replace the red text above with the (full) URL to your login screen.
Hope this works for you! :)
Chris
Re: [chris] Using CMSBuilding Login
I ahve the page films.php, but going there takes me to the login which then takes me to admin. If I then click on view site it takes me to the main page of the site and clicking on the fims link then takes me to admin, as I am now logged in. It never actually lets me the see the page I'm trying to view.
Re: [chris] Using CMSBuilding Login
By Chris - September 3, 2009
Yes, you can redirect someone back to a page after they've logged in.
if (!@$_SESSION['username']) { header("Location: http://example.com/cmsAdmin/admin.php?redirectUrl=" . $_SERVER['REQUEST_URI']); exit; }
That code will pass along the URL of the current page, so that after someone logs in, they'll be sent back.
Hope this helps! :D
Chris
Re: [chris] Using CMSBuilding Login
By Kenny - September 7, 2009 - edited: September 7, 2009
This helps if you want to use CMSB as a user management tool, but not really give them access to the CMSB back end.
1. Create an account with no access to CMSB (None)
2. Create a login page (login.php)
<form method="post" action="http://www.yourdomain.com/cmsAdmin/admin.php">
<input type="hidden" name="action" value="loginSubmit" />
<input type="hidden" name="redirectUrl" value="http://www.yourdomain.com/test/page.php" />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Login</td>
</tr>
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Username</td>
<td>Password</td>
<td></td>
</tr>
<tr>
<td><input type="text" name="username" id="username" value="" size="12" tabindex="1"/> </td>
<td><input type="password" name="password" value="" size="12" tabindex="2"/> </td>
<td><input type="submit" name="login" value="Login" tabindex="4" /> </td>
</tr>
</table>
<script type="text/javascript">
document.getElementById('username').focus();
</script>
</td>
</tr>
</table>
</form>
3. Protect the pages you want to protect using the CMSB Sessions
<?php if (!defined('START_SESSION')) { define('START_SESSION', true); }
require_once "/home/pathto/public_html/cmsAdmin/lib/viewer_functions.php";
if (!@$_SESSION['username']) { header("Location: http://www.yourdomain.com/test/login.php"); exit; }
4. Change the values in red to match your site variables
This is pretty basic in mock up and there can be a lot more styling.
In addition, if you want to create a logout function separate from CMSB (so they are not redirected to the CMSB login screen) create a file called logout.php and link to it:
<?
session_start();
session_destroy();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Logout</title>
</head>
<body>
<script type="text/javascript">
<!--
window.location = "http://www.yourdomain.com/test/login.php"
//-->
</script>
</body>
</html>
Let me know if I missed something. I tested this only briefly.
Kenny