I have the CI script installed on Xampp. Currently I am working on forms and when I click on submit on html, it does nothing.
I tried
echo form_open('verifylogin');
echo form_open();
It show on sourcecode as
<form action="http://::1/codeigniter/verifylogin">
<form action="http://::1/codeigniter/">
respectively.
I don't understand what this "http://::1/"
is and how to get rid of it?
If ip address is displayed in form action or url
http://::1/yourproject/
http://127.0.0.1/yourproject/
Chances are you have left the base url blank
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = '';
Now days in latest versions of codeIgniter it is not recommend that you leave your base_url blank.
$config['base_url'] = 'http://localhost/yourproject/';
$config['base_url'] = 'http://www.example.com/';
And is always good to end url with /
You may need to create routes for your form here
application > config > routes.php
CodeIgniter 3: Routing
CodeIgniter 2: Routing
Update:
With CodeIgniter 3 + versions:
When you create a file remember you will have to have first letter ONLY upper case on file names
and classes
.
What will happen sometimes is that it all may well work in a localhost environment with lower case but when you go to a live server some times will throw errors or not submit forms correct etc.
Example: From Controllers This also applies to Models
File name: Verifylogin.php
<?php
class Verifylogin extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
}
}
File name: Verify_login.php
<?php
class Verify_login extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
}
}
File name: verifylogin.php
class verifylogin extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
}
}
File name: Verify_Login.php
class Verify_Login extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
}
}
Codeigniter Doc's
Go to application/config/config.php set base_url
$config['base_url'] = 'http://localhost/example/';
And refresh your application
Then ::1
error should be gone.
Go to System/core/Config.php
Set config in line 84
public function __construct()
{
$this->config =& get_config();
// Set the base_url automatically if none was provided
if (empty($this->config['base_url']))
{
// The regular expression is only a basic validation for a valid "Host" header.
// It's not exhaustive, only checks for valid characters.
if (isset($_SERVER['HTTP_HOST']) && preg_match('/^((\[[0-9a-f:]+\])|(\d{1,3}(\.\d{1,3}){3})|[a-z0-9\-\.]+)(:\d+)?$/i', $_SERVER['HTTP_HOST']))
{
$base_url = (is_https() ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST']
.substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
}
else
{
$base_url = 'http://localhost/';
}
$this->set_item('base_url', $base_url);
}
log_message('info', 'Config Class Initialized');
}
Remove / from url
Previous :
<li><a href="/<?=site_url('contacts/create')?>">New Contact</a></li>
After :
<li><a href="<?=site_url('contacts/create')?>">New Contact</a></li>
I solved this problem by removing the "/" in the redirect
Before:
header("Location: /index.php?error=TRUE")
After:
header("Location: index.php?error=TRUE")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.