1 (edited by el_luap 2004-10-22 23:41)

Topic: login in main.tpl

I'm trying to add a small login box to the main page (in main.tpl). The thing is that I'd like it to only show up if the user isn't logged in. I've tried playing around with an if ($cookie['is_guest']) but to be honest I really don't know php all that well and since it's a tpl file - I can't get the code to execute. Here's what I did to main.tpl (the relevant section at least):

<table class="punmain" cellspacing="1" cellpadding="4">
    <tr class="punhead">
        <td class="punhead">
            <span class="puntitle"><pun_title></span><br>
            <pun_desc>
        </td>
    </tr>
    <tr>
        <td class="puncon1">
            <table width="100%"><tr><td>
            <pun_navlinks><br><br>
            <pun_status>
            </td>
                echo '<td align="right">
                <form method="post" action="login.php?action=in" id="login">
                <input type="hidden" name="form_sent" value="1">
                <input type="hidden" name="redirect_url" value="login.php">
                Name: <input type="text" name="req_username" size="11" maxlength="25"><br>
                Password: <input type="password" name="req_password" size="11" maxlength="16"><br>
                </form></td>
        </table>
        </td>
    </tr>
</table>

Any help would be appreciated, thanks!

Re: login in main.tpl

It's not quite that easy. You can't put PHP code in the templates like that. You can however include a PHP script with <pun_include "script.php"> in the place where the login box should appear. In this PHP script you can then check if $cookie['is_guest'] is true and if so, spit out a login box. In order to only have it appear for index.php, you will have to check e.g. $_SERVER['SCRIPT_NAME'].

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

Re: login in main.tpl

Worked like a charm! Thanks a ton - I never would have figured that out on my own. I have managed to do quite a bit on my own - which I mean as the highest compliment to your bb given my level of skill. Thanks for such a great product and your help.

Re: login in main.tpl

Hi ed_luap,

Can you confirm where you put the script.php? How did you include it? I'm confused about the paths.

Thanks