1 (edited by BigOHenry 2011-09-16 19:37)

Topic: External Login - How to get username, id, etc after login(COOKIE)?

Hello, i know, here is a lot of topics with external login or integration, but nothing works or nobody said this example works.
I need integrate external login (logout and registration) from my main page into forum.
adress: XXXXX.cz and forum is: forum.XXXXX.cz

external login script path: XXXXX.cz/site/login_gui.php
forum path: XXXXX.cz/subdom/forum/

1. Need to login into forum, but still need to stay on main page, not into forum
2. Need to be still logged when i will move from main page into forum and back

I have 2 parts of database. A) main database B) forum database...these databeses are connected only at user table.
When i will at main page, i will using only main database (A) + user table from forum database (B).

So i need to login first.
here is my external login script:

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
// Add these lines in the very top of your code
define('FORUM_ROOT', 'subdom/forum/');
require FORUM_ROOT.'include/common.php';

if ($forum_user['id'] == '1')
// Where will we go after login?
$forum_page['redirect_url'] = 'http://www.XXXX.cz/';
$forum_page['form_action'] = forum_link($forum_url['login']);
$forum_page['hidden_fields'] = array(
    'form_sent'    => '<input type="hidden" name="form_sent" value="1" />',
    'redirect_url'    => '<input type="hidden" name="redirect_url" value="'.forum_htmlencode($forum_page['redirect_url']).'" />',
    'csrf_token'    => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />',
    'main_login'    => '<input type="hidden" name="main_login" value="1" />'

echo "".$forum_user['username']." ".$forum_user['id']."";

<div id="container">
  <div id="topnav" class="topnav"> <a href="index.php?p=f_reg" class="register"><span>Registrovat</span></a><a href="login" class="signin"><span>Přihlásit</span></a> </div>
  <fieldset id="signin_menu">
    <form method="post" id="signin" action="<?php echo $forum_page['form_action'] ?>">
    <?php echo implode("\n\t\t", $forum_page['hidden_fields'])."\n" ?>
      <label for="username">Uživatelské jméno</label>
      <input id="username" name="req_username" value="" title="username" tabindex="4" type="text"/>
        <label for="password1">Heslo</label>
        <input id="password1" name="req_password" value="" title="password1" tabindex="5" type="password"/>
      <p class="remember">
        <input id="signin_submit" value="Přihlásit" tabindex="6" name="login" type="submit"/>
        <input id="remember" name="save_pass" value="1" tabindex="7" type="checkbox"/>
        <label for="remember">Pamatovat přihlášení</label>
      <p class="forgot"> <a href="#" id="resend_password_link">Zapoměli jste jméno nebo heslo?</a> </p>
        echo "<div id=\"user_logged\" ><p>".
                            "<label> Přihlášen: ". $forum_user['username'] ."</label>".            
                            "<input type=\"button\" alt=\"Tlačítko Muj ucet\" value=\"Můj účet\" onclick=\"window.location.href='index.php?p=my_gui'\" />".
                            "<input type=\"button\" alt=\"Tlačítko odhlásit\" value=\"Odhlásit\" onclick=\"window.location.href='index.php?p=logout'\"  />".    



When i loggin from external login. It said :

Probably you were logged in, but do not have cookies enabled. Change the settings so your browser so that cookies enabled for this site.

and the adress is: XXXXX.cz/index.php?login=1

if i refresh page i am logged into forum, but i go back on main page i still see login form...

part of config.php

$cookie_domain = '';
$cookie_path = '/';

Could anyone help me pls with this? using punBB 1.3.5

2 (edited by BigOHenry 2011-09-16 19:40)

Re: External Login - How to get username, id, etc after login(COOKIE)?

Nice! Cross loggin solved smile
i put this code into forum/login.php on line 114:

if($_POST['main_login'] == 1)
            redirect('http://XXXX.cz', $lang_login['Login redirect']);
            redirect(forum_htmlencode($_POST['redirect_url']).((substr_count($_POST['redirect_url'], '?') == 1) ? '&amp;' : '?').'login=1', $lang_login['Login redirect']);

and add one hidden input into my main login form.

I can loggin sucessfuly from forum page or main page. But at main page can get user status. Still getting username Guest and id 1 from $forum_user['username'] and $forum_user['id'].
Help pls.... sad

3 (edited by the-golem 2011-10-26 11:27)

Re: External Login - How to get username, id, etc after login(COOKIE)?

Instead of

if ($forum_user['id'] == '1')

Try using this instead:

if ($forum_user['is_guest'])