1 (edited by Cailean 2004-03-09 02:31)

Topic: login.php as start page

Hi everyone!

I need to make a wee code edit to have the login box appear on index.php... or, on second thought, should I just do an index.html with a redirect to login.php?

Basically, guests cannot view my forum so I'm trying to save my members a step by not having to click on the 'Login' link.

Edit:
I wasn't sure if this question should go here or in 'Troubleshooting' or somewhere else... there doesn't seem to be a place for questions about small code edits that aren't bugs or full mods.

Find what you want...  Where you want it... www.truelocal.com

Re: login.php as start page

i'm trying to make a login thing on my index.php as well..that uses the userdata of punbb.. see http://www.dutcholsentwins.com
(no success yet though, didn't get it to work yet)

3

Re: login.php as start page

I've managed to get it working on a site I've been playing with.  Here's how...

First I created a file called db.php that loads the punbb abstraction layer...  (most of the code found in this file was posted in these forums earlier)

<? 

// Database abstraction layer from Punbb

// We add the forums directory to the PHP path so that PHP can find the scripts we include later
set_include_path(get_include_path().':[b]./path/to/punbb[/b]');

@include_once 'config.php';

// If PUN isn't defined, config.php is missing or corrupt
if (!defined('PUN'))
    exit('config.php doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');

// The next line tells PunBB to not update the cookie of the visiting user
// A visit to the front page shouldn't affect stuff like new post indicators
define('PUN_DONT_UPDATE_COOKIE', 1);
include_once 'include/common.php';

?>

Next I inserted the following code into my index.php file.

<?php

include_once("db.php");

if (!isset($cur_user[id])) {  // If the current user has not logged in already

     echo "<form action=\"".$g_root."modules/forums/login.php?action=in\" method=\"post\">\n";
     echo "<input type=\"hidden\" name=\"form_sent\" value=\"1\" />\n";
     echo "username <input type=\"text\" name=\"req_username\" size=\"20\" />\n";
     echo "<br />password <input type=\"password\" name=\"req_password\" size=\"20\" />\n";
     echo "<input type=\"submit\" value=\"login\" />\n";
     echo "</form>\n";

}

else {  // Print greeting

     echo "Hello $cur_user[username]";

}

?>

Hope that makes sense.  I'm a complete novice when it comes to PHP and SQL, but I enjoy having a go at it.

grommet

4

Re: login.php as start page

Shoot, I forgot to change one of my global variables...

Change

     echo "<form action=\"".$g_root."modules/forums/login.php?action=in\" method=\"post\">\n";

To

     echo "<form action=\"[b]path/to/punbb[/b]/login.php?action=in\" method=\"post\">\n";

I should probably register, so next time I can edit my post.

grommet

5

Re: login.php as start page

Man I'm dumb...

Ignore the [bold] [/bold] tags.  Thought it would register as bold in my post.  Apparently not in code blocks.

Last post for the evening... I promise.

grommet

Re: login.php as start page

If you want to redirect to the login page instead of showing the "Guests aren't allowed..." page, you can do the following code edit. Open up index.php and replace

if ($cookie['is_guest'] && $pun_config['p_guests_read'] == '0')
        message($lang_common['Login required']);

with

if ($cookie['is_guest'] && $pun_config['p_guests_read'] == '0')
        header('Location: login.php');

Voila!

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: login.php as start page

hmm... Location doesn't stop the script ... should be:

if ($cookie['is_guest'] && $pun_config['p_guests_read'] == '0')
{
        header('Location: login.php');
        exit;
}

IIRC I saw alot of those added between 1.1.1 and 1.1.2 that I jsut upgraded through hdiff wink

Re: login.php as start page

True :) However, index doesn't do any updates so it's not as serious as viewtopic.php. It should be corrected like you pointed out none the less.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

9 (edited by Cailean 2004-03-09 12:39)

Re: login.php as start page

Rickard wrote:

Voila!

Thanks once again Rickard!  Exactly what I was looking for.

Find what you want...  Where you want it... www.truelocal.com