Keep in mind that everything works fine in my program without this code. After I added the code I go to mysite.com/index.php/site/login and chrome tells me:
"This webpage has a redirect loop
The webpage at mysite.com/index.php/site/login has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer."
Here is my controller code for site/login
public function actionLogin()
{
$this->layout='login';
$model=new LoginForm;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('model'=>$model));
}
Anybody have any idea what is causing the problem here when I switch on the UrlManager???
This is an unusual set of rules, which probably routes all requested urls to a single route of ‘video/player’. When ‘video/palyer’ needs authentication, then it will redirect the request to the login page, but when the user’s browser has requested the login page, then it will be routed to ‘video/player’ … infinite loop.
So, what do you want to do with the rules?
[/s]
[EDIT] Sorry, I have misunderstood the problem. Let me think for a while …
Goes to login --> You have to be loggend in before you can see this page --> Goes to login --> You have to be logged in before you can see this page --> …
Isn’t there something in your SubdomainLogin class that can be affected by the url rule?
class SubdomainLogin extends CBehavior
{
/* This method will receive the application as an argument. The attachEventHandler() function attaches to the application an event handler, saying that when the onBeginRequest event occurs, this class’s handleBeginRequest() method should be called. */
public $domain;
public function __construct()
{
$this->domain=explode('.', $_SERVER['HTTP_HOST']);
}
public function attach($owner)
{
$owner->attachEventHandler('onBeginRequest', array($this, 'handleBeginRequest'));
}
public function handleBeginRequest($event)
{
// Check to see if the user is logged in or if they are on the login page, if so ignore
if (Yii::app()->user->isGuest && !$this->onLoginPage())
{
if ($this->checkForSubdomain())
{
if ($this->validateSubdomain())
{
// The subdomain is valid, redirect to the login page
//Yii::app()->user->loginRequired();
} else {
// The subdomain is not valid
}
}
}
}
public function onLoginPage(){
// Check to see if their is a GET variable 'r'
if (isset($_GET['r']))
{
if (strpos($_GET['r'], 'login')!==false)
{
return true;
} else {
return false;
}
}
return false;
}
public function checkForSubdomain()
{
if (count($this->domain)!==3)
{
return false;
}
else if ($this->domain[0]=='www')
{
return false;
}
return true;
}
public function validateSubdomain()
{
// Check to make sure there are only three pieces
if (!(count($this->domain)==3))
{
return false;
} else {
// Check to see if the domain is valid
$client=new Client;
$client=Client::model()->find(array(
'select'=>'id',
'condition'=>'sub_domain=:sub_domain',
'params'=>array(':sub_domain'=>$this->domain[0])
));
// If the record exists then write it to the session
if ($client===null)
{
// Do something to show the subdomain does not exist
return false;
} else {
Yii::app()->session['client_id']=$client->id;
return true;
}
}
}
}
I am going to have to take a step back and see how this is working. Right now, it is working how I want but I am not sure how because I commented out the
Yii::app()->user->loginRequired();
in the SubdomainLogin class. For instance, if someone goes to www.mysite.com it will show the regular public layout. But if they go to subdomain1.mysite.com. It will show the login page for their particular subdomain. That is the action I want and it is working, but I think I need to refactor and straighten some things out.