News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

Login form question SMF 2.0 SSI.php

Started by Wcool, August 14, 2011, 03:10:57 PM

Previous topic - Next topic

Wcool

Hello,

This is my first post. 8)
I don't know if it's in the right section, because there are so much boards with support and helping categories, if it isn't in the right section, please alert me so it can be moved by admin or moderator :)

I know that you guys must be almost exhausted of so many topics of this subject, but I couldn't find it and am trying things for over 3 long days now, so I hope it's ok if there's place for one solution, sorry again. :-[

The problem:

I would like to have a simple login form on my website with username and password and a login button, and here comes the tricky part of which I don't know if it's possible to do.

I would like that the user can log in without redirecting to the login form of SMF itself, so login form on the home page with the ability to log in there without a redirect to another page and if the user has been logged that the form disappears and that the log out textlink will be in it's place.

I have pretty good HTML / CSS skills, only some basic PHP skills. But I'm still busy to learn PHP.
So the login form wouldn't be that much of a problem i think, only the back-end programming.

Hope somebody is able to help me out with this (minor / huge) problem.

Kind Regards,

Wcool

edit:

I'm using following code from the documentation / wiki guide on how to use the user system outside of SMF http://wiki.simplemachines.org/smf/How_to_use_the_SMF_user_system_outside_of_SMF:


<?php require_once("/home/<hosting-username>/public_html/content/smf/SSI.php"); ?>

<?php
if ($context['user']['is_guest'])
{
ssi_login();
}
else
{
//You can show other stuff here.  Like ssi_welcome().  That will show a welcome message like.
//Hey, username, you have 552 messages, 0 are new.
ssi_logout();
}
?>


Only testing this on blank PHP file, the form will be placed instead of ssi_login.
Even if I remove ssi_login I am redirected to the forum first for logging in.
Because of the much failures I had I am just guessing some code now, which I know, isn't very professional nor good :-(

Sir Osis of Liver


You're making a huge project out of a simple request.  If I understand correctly, you want a header login, which many themes have.  Which theme are you using?

When in Emor, do as the Snamors.
                              - D. Lister

Wcool

I'm using the standard curve theme.

Let me explain further:

I would like to have a login form on my own coded website, so totally different from SMF.
I am only trying things out on a blank PHP file before beginning to code a large document with no ending, if you know what I mean.
Unfortunately in my project there's no room to put the website in the forum header and such.
It's a separate website with a forum.
And yes, the header login will be good for the login form on my own coded website then.

Hope to be clear enough now if I wasn't in my first post  ;)

Unfortunately, Krash. , it isn't an option for me to edit the forums theme to include my own pages, navigation etc. I would of course if that was possible for my project.

edit: isn't there a simple piece of code for the form which sends it's data to login2, including the session and such without being redirected.
More work coming: I would really appreciate a solution without customizing the smf source code so upgrades can be done easily, I know it's a tough question, But that's just me, always complicated :P

I'll try to fiddle something with the curve template, not cutting nor paste, only copy :)

Sir Osis of Liver

You can use SSI.php to display the forum login on your website, so there would be one login for both.  Don't know if that would solve your problem, but have a look here -

http://docs.simplemachines.org/index.php?topic=400.0

I can dig up the code for a simple header login if you need it.

When in Emor, do as the Snamors.
                              - D. Lister

Wcool

That would be great Krash.!

I think that would help me started, a piece of login code and the SSI.php.

Thanks in advance.

Wcool

Sir Osis of Liver

Here's the header login.  It goes in template_body_above() in index.template.php -



echo sprintf($txt['welcome_guest'], $txt['guest_title']);
echo '
  <script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
  <form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '" style="margin: 4px 0;"', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
<input type="text" name="user" class="userlog"  size="10" />
<input type="password" name="passwrd" class="userlog"  size="10" />
<input type="submit" value="', $txt['login'], '" class="button_submit" />
<input type="hidden" name="hash_passwrd" value="" />
<input type="hidden" name="cookielength" value="-1" />
</form>', $context['current_time'],'<br />';




Looks like this.  You can add it to your website with SSI.php.

When in Emor, do as the Snamors.
                              - D. Lister

Wcool

Okay, login works fine, it only mustn't get redirected to the forum index, it must stay at the same page you are at the moment.
Any ideas?

I'll check back tomorrow, catch some sleep now  ;D

Wcool

Sir Osis of Liver

Not sure how to do that, but if you use the SSI login on your webpage, looks like you can set the redirect in SSI.php here:



// Shows a login box.
function ssi_login($redirect_to = '', $output_method = 'echo')
{
global $scripturl, $txt, $user_info, $context, $modSettings;

if ($redirect_to != '')
$_SESSION['login_url'] = $redirect_to;

if ($output_method != 'echo' || !$user_info['is_guest'])
return $user_info['is_guest'];




The board login is handled by /Sources/LogInOut.php, which redirects back to board index.
When in Emor, do as the Snamors.
                              - D. Lister

Wcool

Hmm...Tried to access the page as a guest, but cannot view the page, getting redirected directly to the forum with the login box.
Isn't it possible to just stay on the page, just like you can do with the standard joomla login form? That's the solution I'm looking for...

Any ideas?

I'm running out of ideas with the ssi.php...
The problem with ssi.php is that if you aren't logged you even can't access the page, even if you haven't put any ssi function calls inside the PHP document.

The result I would like to get is that you can access the page, even if you're a guest.
And with the if user = logged, that function I can let the registered, logged users see the content which isn't meant for guests.

Hope that it wouldn't be any too complicated  :-[

Kind Regards,

Wcool

Sir Osis of Liver

Only have time for a quick answer, but as I understand it, SSI allows you to place forum content (i.e., login) on your web pages, but shouldn't affect access to those pages.  You need to use SSI to place the login on your webpage, not the login code itself.  You can use the code I gave you to modify the login widget in SSI.php so it looks/works the same on the forum and website, but you must import it to the website using SSI.  The login redirect would have to go in the SSI login script that I posted above.

Haven't tried any of this, but I'll have some time to tinker with it tonight.  Hopefully, someone who knows more will jump in before then.

When in Emor, do as the Snamors.
                              - D. Lister

Wcool

Cracked it!!

And now I also know why he did the redirect so you couldn't see the page.
For some strange reason I've enabled the function: Block Guest access to forum. That was the culprit. So after disabling you could fill in the form with your credentials!
You can login with the form and you aren't get redirected to another page, my question is solved!

Thanks to everyone who helped me with this problem, thank you VERY VERY MUCH!!!

I haven't tidy up the code below, that still has got to be done and then I can go and create my site!
I LOVE SMF!!

Kind Regards to all of ya,

Wcool

P.S. The code  ;D :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php

//Code snippet from URL: http://www.webcheatsheet.com/PHP/get_current_page_url.php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>

<?php
//By $_SESSION call the current page URL to redirect to, otherwise we'll get stuck at the forum index.
require_once("/home/<username>/public_html/content/smf/SSI.php");
$_SESSION['login_url']=curPageURL();
$_SESSION['logout_url']=curPageURL();
?>

<?php
ssi_login
();
?>

<?php
echo '<br />';
ssi_welcome();
echo
'<br />';
ssi_logout();


if (
$context['user']['is_guest'])
{
echo'You are a guest, hello guest.';
}
else
{
echo'You are definitely a member of one of our registered membergroups.';
}



?>

Wcool

Could somebody look if this code is safe to use for distribution site?
I haven't got the needed PHP skills, it was more a trial and error situation and fiddling with some code to get my solution. :P

Wcool

edit: the code in previous post I mean :P

Advertisement: