Recent Topics

1 Oct 10, 2006 18:20    

After upgrading my 0.9.x Version to the Stable "Serenity" 1.8.2 Version I cannot login / logout or view the profile.

B2 is installed in the directory www.partyshock.de/kolumneblog

The Link to logout now looks like this: http://www.partyshock.de/kolumneblog/htsrv/login.php?action=logout&redirect_to=http%3A%2F%2Fwww.partyshock.de%2Fkolumneblog%2F%3Fblog%3D1%26amp%3Bpaged%3D1%26amp%3Bpage%3D1
and If I click on it, I'm getting:

Not Acceptable
An appropriate representation of the requested resource /kolumneblog/htsrv/login.php could not be found on this server.

If I'm logged out (delete the part with the redirect), the Link to Login again looks like this:
http://www.partyshock.de/kolumneblog/htsrv/login.php?redirect_to=http%3A%2F%2Fwww.partyshock.de%2Fkolumneblog%2F%3Fblog%3D1%26amp%3Bpaged%3D1%26amp%3Bpage%3D1

Again I get the Not Acceptable Message and am only able to login after I delete the part with the redirect.

Somebody knows how to fix it? I visited other B2Evolution Blogs and the part with the redirect seems to work there, so I figured just deleting the redirect in the login.php wouldn't be the right way.

2 Oct 11, 2006 02:30

Seems to be a webserver problem.

Because, if you remove the value after "redirect_to=" in the URL, it works.
The error gets triggered just by using "redirect_to=http" or any other common protocol like "ftp" or the like.
Probably a mod_security (Apache module) issue, which does not let it through because it might get uses as an injection for a script.

The parameter is used by b2evo to redirect to a certain page, after the user has logged in (in this case).

Try the following:
Add the function to /inc/_misc/_misc.funcs.php:


/**
 * Try to make $url relative to $target_url, if scheme, host, user and pass matches.
 *
 * @param string URL to handle
 * @param string URL where we want to make $url relative to
 * @return string
 */
function url_rel_to_same_host( $url, $target_url )
{
	$parsed_url = parse_url( $url );
	if( empty($parsed_url['scheme']) || empty($parsed_url['host']) )
	{ // no protocol or host information
		return $url;
	}

	$target_url = parse_url( $target_url );
	if( ! empty($target_url['scheme']) && $target_url['scheme'] != $parsed_url['scheme'] )
	{ // scheme/protocol is different
		return $url;
	}
	if( ! empty($target_url['host']) )
	{
		if( empty($target_url['scheme']) || $target_url['host'] != $parsed_url['host'] )
		{ // target has no scheme (but a host) or hosts differ
			return $url;
		}

		if( @$target_url['port'] != @$parsed_url['port'] )
			return $url;
		if( @$target_url['user'] != @$parsed_url['user'] )
			return $url;
		if( @$target_url['pass'] != @$parsed_url['pass'] )
			return $url;
	}

	// We can make the URL relative:
	$r = '';
	if( ! empty($parsed_url['path']) )
		$r .= $parsed_url['path'];
	if( ! empty($parsed_url['query']) )
		$r .= '?'.$parsed_url['query'];
	if( ! empty($parsed_url['fragment']) )
		$r .= '?'.$parsed_url['fragment'];

	return $r;
}

Then in /inc/MODEL/users/_user.func.php replace the get_user_login_link() function with the following one:


/**
 * Template tag: Get link to login
 */
function get_user_login_link( $before = '', $after = '', $link_text = '', $link_title = '#' )
{
	global $htsrv_url, $edited_Blog, $generating_static;

	if( is_logged_in() ) return false;

	if( $link_text == '' ) $link_text = T_('Login...');
	if( $link_title == '#' ) $link_title = T_('Login if you have an account...');

	if( !isset($generating_static) )
	{ // We are not generating a static page here:
		$redirect = regenerate_url();
	}
	elseif( isset($edited_Blog) )
	{ // We are generating a static page
		$redirect = $edited_Blog->get('dynurl');
	}
	else
	{ // We are in a weird situation
		$redirect = '';
	}

	if( ! empty($redirect) )
	{
		$redirect = url_rel_to_same_host( $redirect, $htsrv_url );
		$redirect = '?redirect_to='.rawurlencode($redirect);
	}

	$r = $before;
	$r .= '<a href="'.$htsrv_url.'login.php'.$redirect.'" title="'.$link_title.'">';
	$r .= $link_text;
	$r .= '</a>';
	$r .= $after;
	return $r;
}

This will then always use a relative URL for the redirect_to param, if it can be used (i.e. your $htsrv_url is on the same host as your blog, which is the case here).

This only fixes the "Login..." link. There are a few others (e.g. "Logout"). I will fix them also, if your feedback is positive and then commit it for 1.8.3.

3 Oct 11, 2006 22:25

Thank you for your quick response :D

I did as suggested.
At first I got an error message, easily solved by editing the _main.php of my skin. (The normal function has been user_login_link so I had to change that)
I suggest you'll change the get_user_login_link function to user_login_link so that it'll work with the normal skins.

Afer this change I'm able to view the blog, but the login link doesn't appear.

[url=http://www.partyshock.de/kolumneblog/index.php?blog=5]Viewable here[/url]

4 Oct 12, 2006 18:06

user_login_link() uses get_user_login_link(). It just echos it out.
So, if you use get_user_login_link() in your skin, add a "echo " in front of it, or use user_login_link() as before.

So, what was the error, which you've tried to solve by changing your _main.php file?

5 Oct 15, 2006 15:31

Arr Sorry. I did a editing mistake in the user.func.php. :oops:

Login works fine, thx :D

6 Oct 15, 2006 22:57

Fine. So I'll apply the url_rel_to_same_host() function to other places also for 1.9.

7 Nov 01, 2006 18:03

I have this same problem with my webhost.

I made the changes like you suggested and it corrected it for Login link like expected.

Can I change the other links myself or should I just wait for an updated version to be available?

It's not a big deal since I'm the only one that uses it, but it'd be great to see it fixed.

8 Nov 01, 2006 20:33

It's in our repository for 1.9. You would have to manually change the other functions, like e.g. "user_logout_link()" and "user_admin_link()".

9 Nov 01, 2006 20:43

awesome.. the only one I realized that was giving me grief was the email link under posts in the get_msgform_link function so I manually fixed that one for myself until the new version becomes available.

Thanks!

10 Dec 03, 2006 07:30

I am having the same exact problem with 1.81-rc I do not want to have to modify my code. What should I request that my hosting provider do to correct this issue.

By the way, I am even having the problem when I click the email icon next to my name on post!


Form is loading...