Using CMSBuilding Login

25 posts by 9 authors in: Forums > CMS Builder
Last Post: October 8, 2009   (RSS)

By andycal - August 20, 2009

Bingo! Thanks Dave!

Re: [andycal] Using CMSBuilding Login

I've tried the above, but get the following error:

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
High quality residential training for writers, actors & Film Making - Click Here for further information

Re: [Moonworks] Using CMSBuilding Login

By Chris - September 2, 2009

Hi Moonworks,

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.
All the best,
Chris

Re: [Moonworks] Using CMSBuilding Login

By Chris - September 2, 2009

You can't have anything before the <?php ?> block which tries to start the session.

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>

All the best,
Chris

Re: [chris] Using CMSBuilding Login

Thanks, looks like I've been doing it wrong all along.

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?
High quality residential training for writers, actors &amp; Film Making - Click Here for further information

Re: [Moonworks] Using CMSBuilding Login

By Chris - September 2, 2009

Hi Moonworks:

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! :)
All the best,
Chris

Re: [chris] Using CMSBuilding Login

That is working, it brings up the place for accessing admin or says you must login firt, but never takes me to the actual page I want.

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.
High quality residential training for writers, actors &amp; Film Making - Click Here for further information

Re: [chris] Using CMSBuilding Login

By Chris - September 3, 2009

I found a secret feature!

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
All the best,
Chris

Re: [chris] Using CMSBuilding Login

By Kenny - September 7, 2009 - edited: September 7, 2009

Alternatively, you could do the following if you want to hide the CMS login page and give them a more customized login page.
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"/>&nbsp;</td>
<td><input type="password" name="password" value="" size="12" tabindex="2"/>&nbsp;</td>
<td><input type="submit" name="login" value="Login" tabindex="4" />&nbsp;</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