Welcome Guest, Not a member yet? Register   Sign In
Form action problem, duplicated URL
#1

[eluser]kulldox[/eluser]
I'm creating a simple login form. Working on local server.
The site is in
Code:
http://www.kullcms.local/admin/
Facing a problem with form's action in
Code:
views/login.php
.
Have the following:
Code:
<form action="/admin/zone" method="POST" id="loginform">
    <label for="username">Username:</label>
    &lt;input type="text" name="username" id="usr" value="&lt;?php echo set_value('username'); ?&gt;" /&gt;
    &lt;?php echo form_error('username'); ?&gt;<br /><br />
    
    <label for="pwd">Password:</label>
    &lt;input type="password" name="password" id="pwd" value="&lt;?php echo set_value('password'); ?&gt;" /&gt;
    &lt;?php echo form_error('password'); ?&gt;<br /><br />
    
    <label for="pwd"></label>
    &lt;input type="submit" value="Login" name="login" id="submit_butt" /&gt;
&lt;/form&gt;

But after submitting it goes to
Code:
http://www.kullcms.local/admin/www.kullcms.local/admin/zone
.

It's very strange strange.

My config/config.php :
Code:
$config['base_url']    = $_SERVER['SERVER_NAME'].'/admin';
$config['index_page'] = "";

Notice? the url is duplicated(actually the base_url is duplicated) and I don't understand why and where this happens.
Anybody?

FYI, I'm pretty new to CI but experienced enough with PHP Smile

Thanks in advance
#2

[eluser]pistolPete[/eluser]
Did you try using a trailing slash according to the comment in config.php?
Code:
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|    http://www.your-site.com/
|
*/
#3

[eluser]kulldox[/eluser]
Yes, certainly.

But no change.

Forgot to mention that I'm building the application in the following dir structure:
Code:
kullcms.local\app\
kullcms.local\app\admin\
kullcms.local\app\admin\config\
kullcms.local\app\admin\controllers\
kullcms.local\app\admin\errors\
kullcms.local\app\admin\helpers\
kullcms.local\app\admin\hooks\
kullcms.local\app\admin\language\
kullcms.local\app\admin\libraries\
kullcms.local\app\admin\models\
kullcms.local\app\admin\views\
kullcms.local\app\admin\index.php
kullcms.local\app\site\
kullcms.local\app\site\config\
kullcms.local\app\site\controllers\
kullcms.local\app\site\errors\
kullcms.local\app\site\helpers\
kullcms.local\app\site\hooks\
kullcms.local\app\site\language\
kullcms.local\app\site\libraries\
kullcms.local\app\site\models\
kullcms.local\app\site\views\
kullcms.local\app\site\index.php
kullcms.local\lib\
kullcms.local\www\
kullcms.local\www\admin\
kullcms.local\www\admin\css\
kullcms.local\www\admin\img\
kullcms.local\www\admin\js\
kullcms.local\www\admin\index.php
kullcms.local\www\css\
kullcms.local\www\img\
kullcms.local\www\js\
kullcms.local\www\index.php
kullcms.local\www\.htaccess
kullcms.local\.htaccess

'kullcms.local\.htaccess':
Code:
AddDefaultCharset utf-8

Options +FollowSymLinks -Indexes

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /www/$1 [L]

which redirects everything to www/ folder which I treat as public dir.

Then in 'kullcms.local\www\.htaccess' I have:
Code:
RewriteEngine On

RewriteCond $1 !^(admin\.php|images|robots\.txt|.*\..*)
RewriteRule ^admin(.*)$ /admin/index.php/$1 [L]

RewriteCond $1 !^(index\.php|images|robots\.txt|.*\..*)
RewriteRule ^(.*)$ index.php/$1 [L]

AddDefaultCharset utf-8

which redirects the requests to admin and front-end site respectively. I'm working on the admin part for now.

But I don't think they are the cause.

I suspect the problem is with the redirect() method from the url helper.
#4

[eluser]jurosik[/eluser]
hi, your base url should end with slash
Code:
$config['base_url']    = $_SERVER['SERVER_NAME'].'/admin/';

and in form action, you should try to use CI form helper
Code:
form_open('admin/zone', array('id' => 'loginform'));

hope, this will help..
#5

[eluser]kulldox[/eluser]
[quote author="jurosik" date="1249863581"]hi, your base url should end with slash
Code:
$config['base_url']    = $_SERVER['SERVER_NAME'].'/admin/';

and in form action, you should try to use CI form helper
Code:
form_open('admin/zone', array('id' => 'loginform'));

hope, this will help..[/quote]

Appreciate your reply but no effect Sad

still goes to
Code:
http://kullcms.local/admin/zone/kullcms.local/admin/zone
.
#6

[eluser]jurosik[/eluser]
did you try it with 'app/' ?
Code:
form_open('app/admin/zone', array('id' => 'loginform'));
#7

[eluser]kulldox[/eluser]
[quote author="jurosik" date="1249864606"]did you try it with 'app/' ?
Code:
form_open('app/admin/zone', array('id' => 'loginform'));
[/quote]

Man, this can't work for sure. There is now 'app' controller and no such folder Smile.

The problem is that the request is duplicated somehow. It creates the url like:
Code:
http://(base_url)/(base_url)/(actual_request)
.
#8

[eluser]kulldox[/eluser]
Sad, but the only way I could fix that is editing the url_helper.php by commenting the preg_match if and changing it to the following:
Code:
// ------------------------------------------------------------------------

/**
* Header Redirect
*
* Header redirect in two flavors
* For very fine grained control over headers, you could use the Output
* Library's set_header() function.
*
* @access    public
* @param    string    the URL
* @param    string    the method: location or redirect
* @return    string
*/
if ( ! function_exists('redirect'))
{
    function redirect($uri = '', $method = 'location', $http_response_code = 302)
    {
//        if ( ! preg_match('#^https?://#i', $uri))
        if ( !isset($uri) )
        {
            $uri = site_url($uri);
        }
        
        switch($method)
        {
            case 'refresh'    : header("Refresh:0;url=".$uri);
                break;
            default            : header("Location: ".$uri, TRUE, $http_response_code);
                break;
        }
        exit;
    }
}
#9

[eluser]Rajeswar[/eluser]
use in form page
&lt;form id="authentication_rent" action="&lt;?= site_url('irent/login');?&gt;" method="post" &gt;
irent is the controller class, in that i have created function login

I think this will solve your problem..




Theme © iAndrew 2016 - Forum software by © MyBB