Welcome Guest, Not a member yet? Register   Sign In
Community Auth - problem
#1

Hallo ,

test admin user pass successfully .
But when I was redirect to \examples\login , I have this error message :

A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant LOGIN_PAGE - assumed 'LOGIN_PAGE'
Filename: config/routes.php
Line Number: 55


My ROUTES.PHP:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route[LOGIN_PAGE] = 'examples/login';


I don't know what is wrong ?

Thanks.

Martin
Reply
#2

(10-22-2015, 01:52 PM)MartinMIB Wrote: A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant LOGIN_PAGE - assumed 'LOGIN_PAGE'
Filename: config/routes.php
Line Number: 55

This is incorrect:
PHP Code:
$route[LOGIN_PAGE] = 'examples/login'

Should be:
PHP Code:
$route['LOGIN_PAGE'] = 'examples/login'

You are missing the single quotes
Reply
#3

LOGIN_PAGE is a constant, so you DO NOT put quotes around it. If PHP is complaining that it is not defined, then you have not defined it, which means it is probably not added to your auth_constants.php hook. If auth_constants.php exists in your application/hooks directory, then you must ensure that hooks are enabled in config/config.php, and that the hook is defined in config/hooks.php. All of this is well documented, so please take the time to re-read the documentation.
Reply
#4

(10-23-2015, 05:48 PM)skunkbad Wrote: LOGIN_PAGE is a constant, so you DO NOT put quotes around it. If PHP is complaining that it is not defined, then you have not defined it, which means it is probably not added to your auth_constants.php hook. If auth_constants.php exists in your application/hooks directory, then you must ensure that hooks are enabled in config/config.php, and that the hook is defined in config/hooks.php. All of this is well documented, so please take the time to re-read the documentation.

Why would you want to use a constant as an array key?
When you set a varialble or key name incorrectly you get this PHP error.
Reply
#5

(10-24-2015, 10:02 AM)Martin7483 Wrote:
(10-23-2015, 05:48 PM)skunkbad Wrote: LOGIN_PAGE is a constant, so you DO NOT put quotes around it. If PHP is complaining that it is not defined, then you have not defined it, which means it is probably not added to your auth_constants.php hook. If auth_constants.php exists in your application/hooks directory, then you must ensure that hooks are enabled in config/config.php, and that the hook is defined in config/hooks.php. All of this is well documented, so please take the time to re-read the documentation.

Why would you want to use a constant as an array key?
When you set a varialble or key name incorrectly you get this PHP error.

Why would you want to use a constant as an array key? Because you can. Community Auth uses this constant to set a route to the login page. You can change this easily because it is a constant, and it would be updated throughout your application. If you're really interested to see how it works, you might spend some time browsing the Community Auth repo and docs.

As for your suggestion that when a variable or key name is set incorrectly that you get "this PHP error", perhaps you should go up to the origin post and see that this error is directly related to the constant not being defined. This only happens when the constant isn't defined, and this can happen for reasons I have already described. This has nothing to do with a constant being used as an array key, which is perfectly acceptable use of PHP.

Your misunderstanding of the way the LOGIN_PAGE constant works, the way PHP works, and the way Community Auth works doesn't change the real answer to the original problem. Please do not answer questions about Community Auth unless you are absolutely sure you are correct, because in this case you are not.
Reply
#6

@skunkbad
No need to go insulting me. I admit I misunderstood the question, as I did not take notice of the fact that it was a rule for a route being set.

As for not knowing how PHP works. Take the following which could be typos in any code:
PHP Code:
$variable some_value;

$array = array();
$array[some_key] = some_value_2

some_value, some_key and some_value_2 are not constants I need, but a simple typo which give these PHP errors
Notice: Use of undefined constant some_value - assumed 'some_value'
Notice: Use of undefined constant some_key - assumed 'some_key'
Notice: Use of undefined constant some_value_2 - assumed 'some_value_2'
Reply
#7

(10-25-2015, 01:33 AM)Martin7483 Wrote: @skunkbad
No need to go insulting me. I admit I misunderstood the question, as I did not take notice of the fact that it was a rule for a route being set.

As for not knowing how PHP works. Take the following which could be typos in any code:

PHP Code:
$variable some_value;

$array = array();
$array[some_key] = some_value_2

some_value, some_key and some_value_2 are not constants I need, but a simple typo which give these PHP errors
Notice: Use of undefined constant some_value - assumed 'some_value'
Notice: Use of undefined constant some_key - assumed 'some_key'
Notice: Use of undefined constant some_value_2 - assumed 'some_value_2'

Sorry, I wasn't trying to insult you.

I'll explain LOGIN_PAGE, so you can understand why it must be a constant, and what a constant is appropriate in this case.

If you dig around in Community Auth you would find that the routes.php file sets a special route to the main login page, and yes the key is the LOGIN_PAGE constant, which is declared in a pre-system hook. This is necessary because no CI config is available at that point. The idea here is that LOGIN_PAGE can be anything you want. On your site, if you want everyone to login at /rainbows/unicorns, then you just set the value of LOGIN_PAGE to /rainbows/unicorns. If you try to access /examples/login directly, you get a 404, which is intended, because I want to force people to use /rainbows/unicorns. Why this? Well, sometimes bots will hammer away on certain login pages; most people are familiar with wp-login.php getting hammered (if they are WordPress users). So now if /rainbows/unicorns is getting hammered on, just switch it to something else, like /stooges/3, or anything new.

I got the idea to make this part of Community Auth because of WordPress, and attacks on the login, which were a problem for me and many of my clients. This doesn't really help when the login is visible to anybody, but for many sites where the login is an unknown URL (except to staff members or admin users), then this can be quite handy. I'm sure you can think of other reasons why changing the login page URL would be handy.

So yes, LOGIN_PAGE is a constant, and must be a constant because it is declared in a pre-system hook and used in routing config, where CI config is not yet available.
Reply
#8

(10-25-2015, 04:48 PM)skunkbad Wrote:
(10-25-2015, 01:33 AM)Martin7483 Wrote: @skunkbad
No need to go insulting me. I admit I misunderstood the question, as I did not take notice of the fact that it was a rule for a route being set.

As for not knowing how PHP works. Take the following which could be typos in any code:

PHP Code:
$variable some_value;

$array = array();
$array[some_key] = some_value_2

some_value, some_key and some_value_2 are not constants I need, but a simple typo which give these PHP errors
Notice: Use of undefined constant some_value - assumed 'some_value'
Notice: Use of undefined constant some_key - assumed 'some_key'
Notice: Use of undefined constant some_value_2 - assumed 'some_value_2'

Sorry, I wasn't trying to insult you.

I'll explain LOGIN_PAGE, so you can understand why it must be a constant, and what a constant is appropriate in this case.

If you dig around in Community Auth you would find that the routes.php file sets a special route to the main login page, and yes the key is the LOGIN_PAGE constant, which is declared in a pre-system hook. This is necessary because no CI config is available at that point. The idea here is that LOGIN_PAGE can be anything you want. On your site, if you want everyone to login at /rainbows/unicorns, then you just set the value of LOGIN_PAGE to /rainbows/unicorns. If you try to access /examples/login directly, you get a 404, which is intended, because I want to force people to use /rainbows/unicorns. Why this? Well, sometimes bots will hammer away on certain login pages; most people are familiar with wp-login.php getting hammered (if they are WordPress users). So now if /rainbows/unicorns is getting hammered on, just switch it to something else, like /stooges/3, or anything new.

I got the idea to make this part of Community Auth because of WordPress, and attacks on the login, which were a problem for me and many of my clients. This doesn't really help when the login is visible to anybody, but for many sites where the login is an unknown URL (except to staff members or admin users), then this can be quite handy. I'm sure you can think of other reasons why changing the login page URL would be handy.

So yes, LOGIN_PAGE is a constant, and must be a constant because it is declared in a pre-system hook and used in routing config, where CI config is not yet available.

I Think you need to change this in application/config/config.php . The default value is false. like @skunkbad already said that, LOGIN_PAGE is already defined in third_party/community_auth/hooks/auth_constants.php

Quote:$config['enable_hooks'] = TRUE;

Hope it helps.

Thanks.
Reply
#9

I Think you need to change this in application/config/config.php . The default value is false. like @skunkbad already said that, LOGIN_PAGE is already defined in third_party/community_auth/hooks/auth_constants.php

$config['enable_hooks'] = TRUE;

Hope it helps.

Thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB