Login on external page - php echo snippet

Discussion forum for MOD Writers regarding MOD Development.
Locked
Frode789
Registered User
Posts: 119
Joined: Sun Jan 06, 2008 7:57 pm
Location: Norway

Login on external page - php echo snippet

Post by Frode789 »

Solved
Last edited by Frode789 on Mon Feb 06, 2012 4:43 pm, edited 5 times in total.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52143
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Login on external page

Post by Brf »

I am not sure what your question is...
You already gave us the code you want.
Frode789
Registered User
Posts: 119
Joined: Sun Jan 06, 2008 7:57 pm
Location: Norway

Re: Login on external page

Post by Frode789 »

Brf wrote:I am not sure what your question is...
You already gave us the code you want.
Yeah never mind.. I hadn't closed the brackets in the correct order.. haha.
Frode789
Registered User
Posts: 119
Joined: Sun Jan 06, 2008 7:57 pm
Location: Norway

Re: Login on external page

Post by Frode789 »

The link (register) isn't working though. The code works in plain html, but when I try to use it in the php code..

Code: Select all

echo(" <input type='button' value='Register' name='register' class='loginButton' onclick="location.href='/forum/ucp.php?mode=register'">");}
Are the ' ' and " " placed correctly?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52143
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Login on external page - php echo snippet

Post by Brf »

You are using quotes " to delimit your string, so you would need to escape them inside the string \"
Frode789
Registered User
Posts: 119
Joined: Sun Jan 06, 2008 7:57 pm
Location: Norway

Re: Login on external page - php echo snippet

Post by Frode789 »

I fixed it. Just used

Code: Select all

echo("<form method='post' action='".$phpbb_root_path."ucp.php?mode=register'>");
echo("<br /><br />");
echo("Don't have an account? Register!");
echo(" <input type='submit' value='Register' name='register' class='loginButton'>");}
echo("<br /></form>");
For reference, if anyone else was looking for a script like this:

On top of index.php:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH :  './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
// check for logout request
$cp = $_GET['cp'];
// is it a logout? then kill the session!
if ($cp == "logout") {
$user->session_kill();
$user->session_begin();
}
?>
Where you want the login/logout part:

Code: Select all

<?php

/*Start Logout*/
if ($user->data['is_registered']){
?>
Welcome back, 
<?php echo $user->data['username_clean']; ?> | You have <?php echo $user->data['user_unread_privmsg']; ?> new messages!   
<?php
echo("<br /><br />");
echo("<form method='post' action='".$phpbb_root_path."ucp.php?mode=logout&sid=".$user->data['session_id']."'>");
echo("<input type='submit' name='logout' value='Logout' class='loginButton'>");
echo("<br /></form>");
}
/*End Logout*/

/*Start Login Box*/
if (!$user->data['is_registered']){
echo("<form method='post' action='".$phpbb_root_path."ucp.php?mode=login'>");
echo(" Username:");
echo(" <input type='text' name='username' class='loginInput' size='15'>");
echo("<br /><br />");
echo(" Password:");
echo(" <input type='text' name='password' class='loginInput'size='15'>");
echo("<br /><br />");
echo("Remember me: <input type='checkbox' name='autologin'>");
echo(" <input type='submit' value='Login' name='login' class='loginButton'>");
echo("<br /></form>");
echo("<form method='post' action='".$phpbb_root_path."ucp.php?mode=register'>");
echo("<br /><br />");
echo("Don't have an account? Register!");
echo(" <input type='submit' value='Register' name='register' class='loginButton'>");}
echo("<br /></form>");
echo("<br />");
/*End Login Box*/
?>	


The CSS class style for the buttons can be removed or you can make your own.
Locked

Return to “[3.0.x] MOD Writers Discussion”