Skip to content

Instantly share code, notes, and snippets.

@SimonWpt
Created September 8, 2012 18:47
Show Gist options
  • Save SimonWpt/3678531 to your computer and use it in GitHub Desktop.
Save SimonWpt/3678531 to your computer and use it in GitHub Desktop.
TYPO3 - Weiche für 404 oder FE-Login
$TYPO3_CONF_VARS['SYS']['curlUse'] = '1';
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = 'USER_FUNCTION:fileadmin/scripts/pageNotFoundHandling.php:user_pageNotFound->pageNotFound';
<?php
define(LOGIN_URL, 'http://www.example.com/login');
define(NOTFOUND_URL, 'http://www.example.com/page-not-found');
class user_pageNotFound {
function pageNotFound($param, $ref) {
if ($param['pageAccessFailureReasons']['fe_group'] != array(''=>0)) {
header('HTTP/1.0 403 Forbidden');
$url = LOGIN_URL.'?redirect_url=' . $param['currentUrl'];
} else {
$url = NOTFOUND_URL;
}
session_start();
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
session_write_close();
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_COOKIE, $strCookie);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
}
?>
@SimonWpt
Copy link
Author

SimonWpt commented Sep 8, 2012

The author of this source is Michael Cannon:
http://typo3vagabond.com/typo3/redirect-to-login-for-access-denied-typo3-users/

Important

  1. Your need CURL
  2. Use GET/POST for felogin, i.e, redirectMode = getpost
  3. Don't use "link to first subpage", set a direct link the subpage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment