News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Help with "load.php"

Started by BPDFamily.com, March 07, 2019, 08:21:07 PM

Previous topic - Next topic

BPDFamily.com

When someone try to load a internal link that they do not have permissions for, I would like to load a 403 error page.

I presume the area to code  that is on the load page. What coding change would I need to accomplish this?

// Set the template contextual information.
$context['user']['is_mod'] = &$user_info['is_mod'];
$context['current_topic'] = $topic;
$context['current_board'] = $board;

// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
if (!empty($board_info['error']) && ($board_info['error'] != 'access' || !$user_info['is_mod']))
{
// The permissions and theme need loading, just to make sure everything goes smoothly.
loadPermissions();
loadTheme();

$_GET['board'] = '';
$_GET['topic'] = '';

// If it's a prefetching agent, just make clear they're not allowed.
if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
{
ob_end_clean();
header('HTTP/1.1 403 Forbidden');
die;
}
elseif ($user_info['is_guest'])
{
loadLanguage('Errors');
is_not_guest($txt['topic_gone']);
}
else
fatal_lang_error('topic_gone', false);
}

if ($user_info['is_mod'])
$user_info['groups'][] = 3;
}

Arantor

Users already get an error message, what exactly are you trying to do that's different?

BPDFamily.com

I want to link to a 404 page instead of the standard message.

BPDFamily.com

I would really appreciate help with this.  Google struggles with that handling of unavailable links.

Aleksi "Lex" Kilpinen

Quote from: BPDFamily.com on March 09, 2019, 12:29:39 PM
I would really appreciate help with this.  Google struggles with that handling of unavailable links.
There is a mod for 2.0 that adds to thre default error handling, I am not aware of a solution for 1.1 though.
( The mod in question is 404 on Missing Topics/Boards )

I am a bit curious though, how does Google choke on the default behaviour? I never saw it as an issue when I was running 1.1.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Arantor

This is why I asked what you were trying to do; redirecting to a page that says something is very different to notifying Google about a page being 404.

Assuming you're not trying to do any redirection that you don't need to, and you just want to mark a page as 404, you don't touch Load.php at all, instead you change Errors.php, but that depends on whether you're really using 1.1.x or 2.0, are you definitely using 1.1.x? (And if so, are you planning on upgrading to anything that isn't 13 years old any time soon?)

This is solved in 2.1 though.

@Lex non-missing pages return HTTP 200 so Google thinks they should be indexed.

Aleksi "Lex" Kilpinen

Quote from: Arantor on March 09, 2019, 12:45:25 PM
@Lex non-missing pages return HTTP 200 so Google thinks they should be indexed.
Oh, right - I can see how that might grow to be an issue over time.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Doug Heffernan

A bt off topic here, but may I ask why you are still using such an old version? The 2.0x version is much much better and 2.1. will be even better.

BPDFamily.com

Quote from: Arantor on March 09, 2019, 12:45:25 PM
This is why I asked what you were trying to do; redirecting to a page that says something is very different to notifying Google about a page being 404.

We want to point here: https://bpdfamily.com/404.shtml

Quote from: Aleksi "Lex" Kilpinen on March 09, 2019, 12:40:41 PM
I am a bit curious though, how does Google choke on the default behaviour? I never saw it as an issue when I was running 1.1.

Google is sending us notes via webmaster tools to resolve the error handling. We recently archived 2 million posts.

Quote from: doug_ips on March 09, 2019, 05:37:02 PM
A bt off topic here, but may I ask why you are still using such an old version? The 2.0x version is much much better and 2.1. will be even better.

The short answer is that the donation tracking software (Resourcez) with 1.1 is working for us and it has generated a significant amount of donations without any error or downtime.

We are operating behind the Securi firewall and have no security issues and spam is a rare.


I'm glad to hear the code exists for 2.0  Can someone lift that code and adapt to 1.1 - or share the code with me?

BPDFamily.com

Kindred

Well, no...   redirecting to that specific URL is what you assumed was the solution.

In reality, as arantor said, to address the actual problem that you pointed out (what google is reporting), the best way to handle it would be to set the header to indicate a 404.

The mod, as pointed out: http://custom.simplemachines.org/mods/index.php?mod=3969
does exactly what you need...   but only works on current/modern versions.

... and you really need to upgrade off of 1.1.x, which is only receiving bare bones support at this point, since it was declared "End of Life".
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

You know that redirecting to that page won't actually change anything, right? It's all about the headers, since the redirection will successfully load that page and you'll be in the same position as you are in now.

BPDFamily.com

Quote from: Kindred on March 10, 2019, 01:37:14 AM
you really need to upgrade off of 1.1.x, which is only receiving bare bones support at this point, since it was declared "End of Life".

I see that there is little support.

Is there a member here that will hire for minor program updates on 1.1?

Aleksi "Lex" Kilpinen

We do try to actively encourage people to adopt versions that are still officially supported.

You can ask for paid support in Help Wanted (not for support)

The code for 2.0 from the mod linked earlier is basically this

./Sources/Errors.php

$error_message = empty($sprintf) ? $txt[$error] : vsprintf($txt[$error], $sprintf);
}

// Include a error code in the header if error message is a certain type:
if ($error == 'no_board' || $error == 'wrong_forum')
{
$request = $smcFunc['db_query']('', '
SELECT MAX(id_board) AS max_board, id_board
FROM {db_prefix}boards
WHERE id_board = {int:board}',
array(
'board' => (int) $board,
)
);
$row = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);
if ($row['max_board'] > $board)
header('HTTP/1.1 404 Not Found');
elseif ($row['id_board'] === null)
header('HTTP/1.1 410 Gone');
else
header('HTTP/1.1 403 Forbidden');
}
elseif ($error == 'not_a_topic' || $error == 'topic_gone')
{
$request = $smcFunc['db_query']('', '
SELECT MAX(id_topic) AS max_topic, id_topic
FROM {db_prefix}topics
WHERE id_topic = {int:topic}',
array(
'topic' => (int) $topic,
)
);
$row = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);
if ($row['max_topic'] > $topic)
header('HTTP/1.1 404 Not Found');
elseif ($row['id_topic'] === null)
header('HTTP/1.1 410 Gone');
else
header('HTTP/1.1 403 Forbidden');
}


This will not work directly in 1.1, and trying will break your forum - just leaving it here as an example in case you can work with it.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF


Kindred

instead of paying for support of an outdated (and, incidentally, insecure*) system...   why not upgrade to at least 2.0.x. 

(* 1.1.21 has known security issues which were not patched because the 1.1.x version is at end of life -- those issues were patched in 2.0.x versions up to 2.0.15)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: