Page Redirection Problem :(

Started by chinmay235, February 26, 2015, 02:36:53 AM

Previous topic - Next topic

chinmay235

I have faced some problem while i am login my account.

Please check my code.


<?php
include('forum/SSI.php');
$_SESSION['login_url']='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; //http://localhost/2015/myproject/index.php
$_SESSION['logout_url']='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; //http://localhost/2015/myproject/index.php
//print_r($_SESSION);exit;
ssi_login();
ssi_logout();
?>





Above code is working fine and page redirected successfully my current page while i am giving correct information.

But when i am giving wrong username and password. Page redirect to the forum log-in page http://localhost/2015/myproject/forum/index.php?action=login2 [nofollow] I want to show error message in the same page.

How i am showing the error message in my current page?




margarett

First things first, you don't need to write to $_SESSION, the function does that for you.

You can call both ssi_login and ssi_logout with a parameter $redirect_to, eg:
ssi_login($redirect_to = 'http://localhost/2015/myproject/index.php');

About your issue, there's really not much that can be done via SSI, I'm sorry. The function sends the login data to SMF's "login2" action and, in that, when you fail the login, you are sent to SMF's login page...

You might get luckier by using the SMF API developed by Andre N, although it is not so simple to use...
http://www.simplemachines.org/community/index.php?topic=453008.0
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

PokémonS

Up

Recently I looking for this too, about how error message from login2 can back to same page using SSI, but no fixes yet.

So I make my own fix.
For example, I make chat.php which is outside SMF.

Look at this code from Sources/LogInOut.php:
// You forgot to type your username, dummy!
if (!isset($_POST['user']) || $_POST['user'] == '')
{


Then add after it:
if (strstr($_SERVER['HTTP_REFERER'], 'pokemonstars.com/forum/chat.php') !== false) {
    header('Location: http://pokemonstars.com/forum/chat.php?error=nouser');
}


Change the URL to your current page. Try login without username and password.
It should work back to your current page.

You'll also need some $_GET to your current page to show the error message.

if ($_GET['error'] == "nouser")
echo "Username is empty";





More

User filled but pass is empty.
// Hmm... maybe 'admin' will login with no password. Uhh... NO!
if ((!isset($_POST['passwrd']) || $_POST['passwrd'] == '') && (!isset($_POST['hash_passwrd']) || strlen($_POST['hash_passwrd']) != 40))
{
if (strstr($_SERVER['HTTP_REFERER'], 'pokemonstars.com/forum/chat.php') !== false) {
    header('Location: http://pokemonstars.com/forum/chat.php?error=nopass');
}
$context['login_errors'] = array($txt['no_password']);
return;
}


User is not exist
// Let them try again, it didn't match anything...
if ($smcFunc['db_num_rows']($request) == 0)
{
if (strstr($_SERVER['HTTP_REFERER'], 'pokemonstars.com/forum/chat.php') !== false) {
    header('Location: http://pokemonstars.com/forum/chat.php?error=usernoexist');
}
$context['login_errors'] = array($txt['username_no_exist']);
return;
}


Wrong password
// We'll give you another chance...
else
{

// Log an error so we know that it didn't go well in the error log.
log_error($txt['incorrect_password'] . ' - <span class="remove">' . $user_settings['member_name'] . '</span>', 'user');
if (strstr($_SERVER['HTTP_REFERER'], 'pokemonstars.com/forum/chat.php') !== false) {
    header('Location: http://pokemonstars.com/forum/chat.php?error=incorrectpass');
}
$context['login_errors'] = array($txt['incorrect_password']);
return;
}
きみと手をつなごう つらいときはもっと
ゼロからはじめよう ほら ほら 手をつなごう
みんな手をつなごう つらいときはもっと
力を合わせよう ほら ほら 手をつなごう

Advertisement: