Welcome Guest, Not a member yet? Register   Sign In
  Helpful Tips!
Posted by: El Forum - 06-27-2008, 09:12 AM - Replies (5)

[eluser]Jamie Rumbelow[/eluser]
I keep on seeing repeatedly asked questions around and about these forums, so I think we should put together a list of CI related FAQs of sorts. These should be related to the coding side of things.

Good Idea?


  (SOLVED)Need Login Help using Erkanaauth
Posted by: El Forum - 06-27-2008, 07:29 AM - Replies (8)

[eluser]zimco[/eluser]
I'm trying to create the most basic login area for my application: one admin user and password stored in a mysql table.

I tried following the tutorial by Alex Biddle that uses Erkanaauth but i've mucked it all up and can't get it to work.

Can someone tell me what i am doing wrong and how to fix it?

File locations:
application/libraries/Erkanaauth.php
application/helpers/erkanaauth_helper.php
application/controllers/admin/authcontroller.php
application/controllers/admin/login.php
application/views/admin/content-login.php

The mysql table was created with the following command:
CREATE TABLE `users` (
`id` smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
`username` varchar(10) NOT NULL,
`password` varchar(10) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
);

The admin user was inserted into the database with
INSERT INTO users (username, password) VALUES ("admin", sha1("demo"));

Here's the code for my login.php controller:

Code:
<?php

class Login extends Controller
{

    function Login()
    {
        parent::Controller();
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css');
        $this->load->library('validation');
        $this->load->helper('form');
        $this->load->library('Erkanaauth');
    }


/*======================================================================*\
    Function:    index()
    Purpose:    Provide the Login entry page.
    Input:        
    Output:        Display login page view
\*======================================================================*/
    function index()
    {
        $login_form_rules = array
        (
            'username' => 'callback_check_username',
            'password' => 'required'
        );
        $login_form_fields = array
        (
            'username' => 'username',
            'password' => 'password'
        );

        $this->validation->set_fields($login_form_fields);
        $this->validation->set_rules($login_form_rules);
        if ($this->validation->run() == FALSE)
        {
          //Load the view file
          $data['css'] = $this->css;
          $data['base'] = $this->base;
          // set the header view
          $data['header'] = $this->load->view('header', '');
          // set the page content
          $data['content'] = $this->load->view('admin/content-login', $data);
          // set the footer view
          $data['footer'] = $this->load->view('footer', '');
        }
        else
        {
            redirect('admin/success');
        }

    }


/*======================================================================*\
    Function:    check_username($username)
    Purpose:    
    Input:        
    Output:        
\*======================================================================*/
    function check_username($username)
    {
        $this->load->helper('security');
        $password = dohash($this->input->post('password'));
        if ($this->erkanaauth->try_login(array('username' => $username, 'password' => $password)))
        {
            return True;
        }
        else
        {
            $this->validation->set_message('check_username', 'Incorrect login info.');
            return False;
        }
    }
    
/*======================================================================*\
                                  END
\*======================================================================*/
}

?>

Here's the code for my login view, content-login.php:

Code:
<div id="content">

<div id="loginform">
<h1>Login</h1>
&lt;?php echo $this->validation->error_string; ?&gt;

&lt;?php $attributes = array('id' => 'login'); ?&gt;
&lt;?php echo form_open('admin/index', $attributes); ?&gt;

  <p>
  <label for="username">Username: </label>
  &lt;?php
  $username = array(
              'username'    => 'username',
              'maxlength'   => '10',
              'size'        => '25',
            );
  echo form_input($username);
  ?&gt;
  <p>
  <label for="password">Password: </label>
  &lt;?php
  $password = array(
              'password'    => 'password',
              'maxlength'   => '10',
              'size'        => '25',
            );
  echo form_input($password);
  ?&gt;
  </p>
  <p>
    &lt;?php echo form_submit('submit', 'Submit'); ?&gt;
  </p>  
  
  &lt;?php echo form_close(); ?&gt;
  
</div>

</div>


  Confused with set_message validation function
Posted by: El Forum - 06-27-2008, 07:07 AM - Replies (4)

[eluser]CARP[/eluser]
Hi guys
I've been trying to replace default error messages when validating my forms, but I cannot get it to work.
After searching in forums, I see that the set_message function is called when using callback functions (custom validation routines) but I won't create 1 custom callback routine for just displaying my custom error message

This is my code

Code:
$rules['usernamefield']     = 'trim|required';
    $rules['emailfield']         = 'trim|required';

    $this->validation->set_message($rules['usernamefield'], 'You must fill this field!');
    $this->validation->set_message('usernamefield', 'You must fill this field!');

    $this->validation->set_rules($rules);
    $this->validation->set_error_delimiters('<span class="error">', '</span><br />');

    $fields['usernamefield']    = 'Your Username';
    $fields['emailfield']    = 'Your Email address';

    $this->validation->set_fields($fields);

but this line
Code:
$this->validation->set_message($rules['usernamefield'], 'You must fill this field!');
nor this one
Code:
$this->validation->set_message('usernamefield', 'You must fill this field!');
aren't working

Should I use set_message only when using callback custom validation functions?

Thanks a lot in adv.


  modifying the codeigniter route structure
Posted by: El Forum - 06-27-2008, 07:05 AM - Replies (2)

[eluser]adamBouchard[/eluser]
Hi,

I am trying to achieve the following url structure similar to what you see if you have a basecamp account from 37 signals:

URL Goal:

customer_name.domain.com/project_name/controller/action

My current url structure is....

domain.com/controller/action/customer_name/project_name


Does anyone know the easiest way to achieve this?

Thanks,

Adam


  How can we generate error log file?
Posted by: El Forum - 06-27-2008, 06:39 AM - Replies (4)

[eluser]Zeeshan Rasool[/eluser]

Quote:Guys!very thnx that you have always been very much coopertive wd me.
Here, I want that when an error occured,the error mesg written in error log file.
here, i copy and add this code in my model from PHP manual,
Code:
function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
    {
    // timestamp for the error entry
    $dt = date("Y-m-d H:i:s (T)");

    // define an assoc array of error string
    // in reality the only entries we should
    // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
    // E_USER_WARNING and E_USER_NOTICE
    $errortype = array (
                E_ERROR           => "Error",
                E_WARNING         => "Warning",
                E_PARSE           => "Parsing Error",
                E_NOTICE          => "Notice",
                E_CORE_ERROR      => "Core Error",
                E_CORE_WARNING    => "Core Warning",
                E_COMPILE_ERROR   => "Compile Error",
                E_COMPILE_WARNING => "Compile Warning",
                E_USER_ERROR      => "User Error",
                E_USER_WARNING    => "User Warning",
                E_USER_NOTICE     => "User Notice",
                E_STRICT          => "Runtime Notice"
                );
        // set of errors for which a var trace will be saved
        $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
        
        $err = "<errorentry>\n";
        $err .= "\t<datetime>" . $dt . "</datetime>\n";
        $err .= "\t<errornum>" . $errno . "</errornum>\n";
        $err .= "\t<errortype>" . $errortype[$errno] . "</errortype>\n";
        $err .= "\t<errormsg>" . $errmsg . "</errormsg>\n";
        $err .= "\t[removed]" . $filename . "[removed]\n";
        $err .= "\t[removed]" . $linenum . "[removed]\n";
    
        if (in_array($errno, $user_errors))
            $err .= "\t<vartrace>" . wddx_serialize_value($vars, "Variables") . "</vartrace>\n";
        $err .= "</errorentry>\n\n";
        
        // for testing
        // echo $err;
    
        // save to the error log, and e-mail me if there is a critical user error
        error_log($err, 3, "/system/logs/error.log");
        if ($errno == E_USER_ERROR) {
                    mail("[email protected]", "Critical User Error", $err);
            }
}


Also there,


The behaviour of these functions is affected by settings in php.ini.


Table 1. Errors and Logging Configuration Options

[code]Name             Default               Changeable
error_reporting        E_ALL & ~E_NOTICE     PHP_INI_ALL
display_errors          "1"                  PHP_INI_ALL
display_startup_errors "0"                   PHP_INI_ALL
log_errors "0"                               PHP_INI_ALL
log_errors_max_len    "1024"                 PHP_INI_ALL
ignore_repeated_errors "0"                   PHP_INI_ALL
ignore_repeated_source "0"                   pHP_INI_ALL
report_memleaks        "1"                   PHP_INI_ALL
track_errors           "0"                   PHP_INI_ALL
html_errors            "1"                   PHP_INI_ALL
docref_root            ""                    PHP_INI_ALL
docref_ext             ""                    PHP_INI_ALL
error_prepend_string  NULL                   PHP_INI_ALL
error_append_string   NULL                   PHP_INI_ALL
error_log             NULL                   PHP_INI_ALL
warn_plus_overloading NULL                   PHP_INI??

problem is that, where shud i make changing and how an error be passed to that function.
when i call that func. through this code.

Also Here , if upload failed then the 'userErrorHandler' func. called

if(!$this->upload->do_upload($video))
        {    
            $errmsg='error ';
            $filename='/system/logs/error.log';
            $linenum='3';
            $vars='';
            $this->userErrorHandler(2047, $errmsg, $filename, $linenum, $vars);}
no result

plz any one who give some trick or other suggession.
thnx in adv.


  global variable codeigniter
Posted by: El Forum - 06-27-2008, 06:13 AM - Replies (3)

[eluser]italoc[/eluser]
i have a file with global variable that i have used for build my webapps now i have imported this webapp in CI but i would like to use the same global variable file.

for example my file is written in this way:

Code:
$icon_add_category = $icon_folder."attach.gif";
$icon_gallery = $icon_folder."images.gif";
$icon_help = $icon_folder."help.gif";

there is a for use this variable as a global variable autoloaded withouth change the sintax?

otherwise what can i do??

thanks..


  getting 404s for my CI urls
Posted by: El Forum - 06-27-2008, 05:42 AM - Replies (13)

[eluser]philk[/eluser]
I'm trying to get a local copy of a site working under WAMP, the index.php loads fine, but the urls linked through CI don't work at all, I just get a generic 404 page, not even the CI 404 page.

I have changed this to local host >

Code:
$config['base_url']    = "http://localhost/";

within config.php but no joy.

If I change the default controller to 'welcome' instead of
Code:
$route['default_controller'] = "pages";

within routes.php, I at least get a CI error message


Code:
An Error Was Encountered

Unable to load the requested file: welcome_message.php

That's as far as I have got, can anyone help. I'm new to all this and more of a designer than a developer, but I need to get the site running locally for the redesign. Thanks


  Redirection to the action i were before/actually
Posted by: El Forum - 06-27-2008, 04:51 AM - Replies (2)

[eluser]kevinh21[/eluser]
Hi everyone,
Following situation:
I have 2 controllers: blog and user(it's the redux authentification library/controller).

I have the following layout that is built in the blog controller:
----------------
|--|--------|--|
|--|-content|--|
|--|--------|--|
----------------

In the right navigation i have the usercontrol panel (login/logout link and things like this).
The logout link refers to the "user/logout" function listed here:

Code:
function logout ()
{
    $this->redux_auth->logout(); // Destroy the session variables.
    redirect('');
}

With the redirect command it will show me the mainpage (controller: blog/index())
even if i was in the blog/viewpost action before.

What i want:
If i'm looking a blogpost and click the logout link on the right side, it should log me out (user/logout()) but then it should redirect me to the page i was before -> viewing a post in this situation (blog/viewpost())

How is this possible?


  Integrating AMFPHP and CodeIgniter -- the EASY WAY!
Posted by: El Forum - 06-27-2008, 04:35 AM - Replies (10)

[eluser]Unknown[/eluser]
How to integrate CodeIgniter and AMFPHP

Start a new PHP file

Create a class called AMFPHP_CI_Integration.php in your amfphp/services folder:

Code:
&lt;?php
    class AMFPHP_CI_Integration
    {
    }
?&gt;

Copy the CodeIgniter framework into your amfphp folder

Create the constructor function for the AMFPHP_CI_Integration.php file:

Code:
function AMFPHP_CI_Integration extends Controller
{
}

Create a CI folder in your amfphp/services folder and create a CodeIgniter.php file:
Code:
&lt;?php
    if (!defined('BASEPATH')) define ("BASEPATH", "../CodeIgniter/system/");
    if (!defined('APPPATH')) define ("APPPATH", "../CodeIgniter/system/application/");
    if (!defined ("EXT")) define ("EXT", ".php");

    require_once (BASEPATH."codeigniter/Base5.php");
    require_once (BASEPATH."libraries/Controller.php");
    require_once (BASEPATH."codeigniter/Common.php");
?&gt;

This file basically just includes all the base CI files in your service

Add the following code to your constructor function of the AMFPHP_CI_Integration.php file:

Code:
parent::Controller ();

and the following code to the top of the file, just below the &lt;?php tag:

Code:
require_once ("CI/CodeIgniter.php");

And you're done! Use CodeIgniter in the way you normally would and enjoy!


  Session problem (duplicate records)
Posted by: El Forum - 06-27-2008, 04:14 AM - Replies (1)

[eluser]adwin[/eluser]
I am still using CI 1.6.2 with FreakAuth 1.1

I got a problem with Session (ci_sessions) because when I tried to load on view
like this

Code:
if($this->freakauth_light->isValidUser())
{
   $obj =& get_instance();    
   $obj->load->library('session');
   echo $obj->session->userdata('ip_address');
}

I notice that my ci_sessions added 1 records. and soon after I refresh this page, I found that my ci_sessions added 1 more records. it also makes me logged out and force me to login again.

my controller was like this
Code:
&lt;?php
    class Test extends Controller{

        function Test(){
            parent::Controller();
            $this->freakauth_light->check();
            $this->_container = $this->config->item('FAL_template_dir').'template/container';    
        }

        function index(){
            $data['heading'] = 'Menu';
            $this->mysmarty->assign('name', 'tester');
            $data['mysmartypage'] = "simply for testing <b> test </b> ";
            $data['message'] = 'this page is for testing purposes only ' ;
            
            $this->load->vars($data);        
            $this->load->view($this->_container);        
        }
    }
?&gt;

am i make any mistakes in here ?


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Array to HTML "Table"
by paulkd
6 hours ago
TypeError when trying to ...
by b126
7 hours ago
Webhooks and WebSockets
by InsiteFX
Yesterday, 10:39 AM
Retaining search variable...
by pchriley
Yesterday, 05:46 AM
Reading a session variabl...
by xanabobana
Yesterday, 05:05 AM
Update to v4.5.1, same us...
by kenjis
04-17-2024, 07:47 PM
Codeigniter 4 extend core...
by Semsion
04-17-2024, 05:08 AM
v4.5.1 Bug Fix Released
by lokman
04-16-2024, 02:12 PM
problem with textarea
by Nitin Arora
04-16-2024, 05:07 AM
Showing pdf on browser
by aarefi
04-16-2024, 04:38 AM

Forum Statistics
» Members: 84,562
» Latest member: i9betcasino
» Forum threads: 77,558
» Forum posts: 375,896

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB