0

我无法使用 Codeigniter 2.1 中的表单访问控制器。主页有几个链接,我可以访问。但是当我想以表单提交数据时,我会显示 403 禁止错误:

禁止您无权访问此服务器上的 /Pruebas/application/controllers/valiar.php。

风景:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Anuncios</title>
<link rel="stylesheet" href="/Pruebas/css/estilos.css" type="text/css"   
    media="screen"/>    
<link rel="stylesheet" href="/Pruebas/css/logestilos.css" type="text/css" 
    media="screen"/>
</head>

<body>

<div id="contenedor">
<div id="menu">
    <label for="home" id="inicio"><a href="http://localhost/Pruebas/index.php 
            /cindice/">Inicio</a></label> 
    <label for="acceso" id="login"><a href="http://localhost/Pruebas/index.php
            /cindice/publicar">Publicar anuncio</a></label> 
    <label for="reg" id="registro"><a href="http://localhost/Pruebas/index.php
            /cindice/registro">Registro</a></label>
    <label for="empresa" id="sobrempresa"><a href="http://localhost/Pruebas
            /index.php/cindice/sobempresa">Sobre nosotros</a></label>
    <label for="contacto" id="contactar"><a href="http://localhost/Pruebas   
            /index.php/cindice/contacto">Cont&aacute;ctanos</a></label>
</div>  
</div>

<div id="acformulario"> 
    <?php echo validation_errors(); ?>
    <form action="http://localhost/Pruebas/application/controllers   
            /validar.php" method="post">
    <label for="correo" id="dcorreo">Direcci&oacute;n de correo</label>
    <input type="text" name="drcorreo" id="dcc"/><br /><br />
    <label for="contrasenya" id="cont">Contrase&ntilde;a</label>
    <input type="password" name="contrasena" id="cmcont"/><br /><br />

    <input type="submit" name="envia" id="bentrar" value="Entrar" />    
    </form>
 </div> 

</body>
</html>

控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

  class Cindice extends CI_Controller {

function __construct() {
    parent::__construct();
}

public function index()
{
    $this->load->view('indice');
}

    public function validar() 
{
    $this->input->post('drcorreo');
    $this->input->post('contrasena');

    $this->form_validation->set_rules('correo','Direcci&oacute;n de  
            correo','trim|required|valid_email|xss_clean');

            $this->form_validation->set_rules('contrasenya','Contrase&ntilde;a',
            'trim|required|md5|xss_clean');

    if ($this->form_validation->run())
     {
        echo ("validaci&oacute;n v&aacute;lida");   
     }
    else {
        $this->load->view('');
        echo ("validaci&oacute;n incorrecta");
         }  
} 

我的 .htacess 文件中包含“deny from all”字样。如何访问控制器?

谢谢。

4

1 回答 1

2

您的表单操作应如下所示:

<?php echo form_open('validar'); // needs the form helper to be loaded ?>

... 代替:

<form action="http://localhost/Pruebas/application/controllers/validar.php" method="post">

您不能将控制器的文件路径作为表单操作的位置。

于 2013-05-13T09:48:23.870 回答