www.webdeveloper.com
Page 8 of 14 FirstFirst ... 678910 ... LastLast
Results 106 to 120 of 198

Thread: My questions thread.

  1. #106
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Another CI Question: How do you guys feel about Helpers? Do they hurt performance much?
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  2. #107
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    Quote Originally Posted by evenstar7139 View Post
    Another CI Question: How do you guys feel about Helpers? Do they hurt performance much?
    Hurt performance as compared to what?

    If they fulfill a functionality that you need/want, then the only seemingly meaningful performance question would seem to be: what alternative solution do you want to compare it to. Ultimately, helpers are just collections of user-defined PHP functions -- the same sort of things we've been using in procedural PHP programs for over a decade. It really should be no different than include()-ing your own file of custom function definitions and using them instead of the helper functions.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #108
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Quote Originally Posted by NogDog View Post
    Hurt performance as compared to what?
    Actually, I don't know. We talked about the active resource methods being too slow to be feasible for use in most queries and I wondered if such applied to the helper functions.

    Anyway, I've been at standstill since yesterday. I'm sitting here, staring at my controllers, wondering how to give them access to methods I'd like to be available sitewide. I've been told over and over to be a DRY programmer, so I'm not going to copy and paste them into each controller. I thought maybe the methods could all go in their own controller, and each controller just load that one, but after a bit of Googling that seems to be a no-no.

    Should I put them in CI's core controller? Or am I not supposed to touch that? If that's the case, should I make a controller that inherits from the core controller, and then have all my other controllers inherit from that one?
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  4. #109
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    There may not be one right answer -- as usual, it's probably an "It depends" sort of thing. If you have functions that (a) are needed by most/all of your controllers and (b) truly reflect controller-level activity, you could create a base (abstract?) class that extends the CI controller and which implements those methods, then have your controllers extend that new class.

    If you're talking about functionality that has less to do with "controlling" than it does with business logic, handling user inputs, or other stuff, then you're more likely looking at either a model (which, by the way, you can specify in your config to be automatically invoked by all controllers), or else put it into either a helper function file or a library class (which again I believe both can be auto-invoked via the config if you want).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #110
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Hmm. That response not only helped, it gave me a lot to think about. One thing I thought about was my old login system and how, on every page, it checked the cookies to see if the person is logged in and, if so, who they are. I think the login system on my old site was insecure, and I was thinking about redoing it for the new one. Do you approve or do you see security holes?

    First off, I digress. I like login systems that don't log you out because you closed the browser. I like them to log somebody out when they want to be logged out, or after a reasonable amount of time, like I think Yahoo! Mail logs you out after two weeks. As far as knowledge, I know very little about sessions because I've barely used them. I used cookies. To my knowledge, sessions always end when the browser is closed.

    So, with that in mind. I was thinking about making it so, when a user logs in, their user ID is encrypted and sent to their cookies, along with an encrypted password that was generated at the time of logging in. (Don't confuse it with the password they use to login. Two different things.) Both the user ID and the password would be in the user table in the database. Every time the person loads a page, the site would decrypt the user ID and password, and compare it to what's in the database. If they're correct, the person stays logged in, if not, they are immediately logged out.
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  6. #111
    Join Date
    Jan 2009
    Posts
    3,346
    I use a nonce column in my session management table that associates a user to an active or previously active session. Then all I have to store for the post session termination reactivation is the nonce code in a cookie. Once a nonce is used I kill that "session" in the db and generate a new one for the current session. This also has the added benefit of giving a little stats you can use to look for possible shared accounts, misuse of authenticated accounts, etc.

  7. #112
    Join Date
    Jul 2012
    Location
    Vancouver
    Posts
    61
    Quote Originally Posted by evenstar7139 View Post
    So, with that in mind. I was thinking about making it so, when a user logs in, their user ID is encrypted and sent to their cookies, along with an encrypted password that was generated at the time of logging in. (Don't confuse it with the password they use to login. Two different things.) Both the user ID and the password would be in the user table in the database. Every time the person loads a page, the site would decrypt the user ID and password, and compare it to what's in the database. If they're correct, the person stays logged in, if not, they are immediately logged out.
    http://codeigniter.com/user_guide/li.../sessions.html

    That's what the session_id is for.. it's hashed and regenerated every 5 minutes of activity and the session settings have ip matching, headers, encryption etc..

    CI does a lot of things for you that otherwise take up a good portion of time to do

  8. #113
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Thank you, I'm reading that now.
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  9. #114
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Okay, I read up on sessions in CI, and have a much better idea how to keep my users logged in. It didn't before occur to me to read this part of the documentation, because I thought I wasn't interested in sessions, but, apparently, CI sessions are different from native PHP sessions.

    So, moving on, I went to work on my default controller, which is called "Home" and I realized some of its content will be static and I don't know where to store it. Home is default because when people go to the site root, I want it to get called. It is my "front page" if you will.

    Well, it's going to load the header and footer. In between those two will be the content area of the page. Some static content will be displayed and then there will be a dynamic area which displays a login form and registration link but only if the person viewing the page is not logged in.

    I did something kind of similar when I did this tutorial: http://codeigniter.com/user_guide/tu...tic_pages.html

    ...but my entire content area is not static, and I changed my default controller from Pages to Home.

    So, what I want to know is, should I type my static content right into the Home controller or should it be contained in "application/views/home/"? How about the dynamic part that decides whether or not to display a form? Should that be coded right into the controller?
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  10. #115
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    Ideally, everything that is HTML or that directly outputs HTML should be in your view. Dynamic data can be transmitted to the view from the controller when the latter loads the view, which the view can then use as it sees fit. As a simple example, in the controller:
    PHP Code:
    $this->load->view('home', array('title' => 'Hello World'); 
    In the view:
    PHP Code:
    <html>
    <head><title><?php echo $title?></title></head>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  11. #116
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    Oh, PS: with the built-in PHP sessions you can control when a user is logged out by changing the related session settings, either in the code or in the PHP config. The default setting for session.cookie_timeout is 0, which means "when the user closes their browser", but you can change it to a non-zero number, which means for that many seconds. (You also then want to adjust some of the other session settings that control how long the session data is retained on the server, namely session.gc_maxlifetime.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  12. #117
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Hello everybody. I have a couple view-related questions.

    #1 Should all my "application/views" subfolders correspond with a controller? Like, should I have "application/views/login" only if I have a controller called "Login"? I understand there are probably different ways to approach this, but what would you guys do?

    #2 Does what I marked by surrounding it with // ---- belong in a controller or is it better off being in a model? Or should it even come from a view? This isn't what the final content is going to be, but it is going to be static rather than populated with results from a database query.

    PHP Code:
            if (!$logged_in)
            {
                
    $this->load->library('table');
                   
               
    // ----         
               
    $items= array(
                array(
    'Name''Color''Size'),
                array(
    'Fred''Blue''Small'),
                array(
    'Mary''Red''Large'),
                array(
    'John''Purple''Medium'),
                ); 
    // ----
                
                
    $data['table'] = $this->table->generate($items);
                
    $this->load->view('home/dynamic'$data);
            } 
    #3 Do you guys put prefixes on the file names of your view files?
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  13. #118
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    #1: Might make sense in many situations, might not in others (e.g. different controllers end up using the same view -- it's possible).

    #2: Depends on it's purpose. If it only exists to drive how the page looks (e.g. column labels) and is not dynamic, then it probably belongs in the view -- though at first glance it looks more like data you extract from a DB? If it's actual dynamic data, then that data can be passed to the view, which can then "decide" how it wants to display it.

    #3: Prefix sounds suspiciously like directory.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  14. #119
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Quote Originally Posted by NogDog View Post
    #1: Might make sense in many situations, might not in others (e.g. different controllers end up using the same view -- it's possible).

    #2: Depends on it's purpose. If it only exists to drive how the page looks (e.g. column labels) and is not dynamic, then it probably belongs in the view -- though at first glance it looks more like data you extract from a DB? If it's actual dynamic data, then that data can be passed to the view, which can then "decide" how it wants to display it.

    #3: Prefix sounds suspiciously like directory.

    #2 The only reason those names, colors, etc. in there are because that's what was in the documentation. I was just copying and pasting because I was only concerned with seeing how the table creator thingy works. What this is actually going to be displayed is similar to what follows:

    PHP Code:
    <small><a href='user/lost_password'>Lost Password?</a> <a href='user/register'>Register.</a></small>
    <
    table>
    <
    form action='user/login' method='post'>
    <
    tr>
       <
    td><strong>Username:</strong></td>
       <
    td><input type='text' name='username' size='15' length='20' /></td>
    </
    tr>
    <
    tr>
       <
    td><strong>Password:</strong></td>
       <
    td><input type='password' name='password' size='15' length='20' /></td>
    </
    tr>
    </
    table>
    <
    input type='submit' value='Log In'>
    </
    form
    So, in the view it goes?

    #3 I read about the prefix thing here: http://codeigniter.com/user_guide/ge...g_common_words I noticed I have multiple files named index.php but never worried about name collisions because I thought the directories they were in was enough to identify them. (Like, there is /index.php, /application/views/home/index.php, /application/views/news/index.php, etc.) That part of the documentation, though, seems to think otherwise. I wondered what you guy's opinion would be.
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  15. #120
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Hello today ^_^ Got some questions for ya.


    #1 Are any of these characters unsafe to allow in a password:

    ~ ! @ # $ &#37; ^ & * ( )

    #2 Is this how my regular expression should look if I'm allowing letters, numbers, underscores, dashes, and all of the characters above:

    PHP Code:
    preg_match("/^([A-Za-z0-9_-~!@#$%^&*()])+$/i"$password

    #3 I'm wondering what to do with fields that don't validate via a preg_match(). Sometimes in my forms, the acceptable answers are a list of strings. Like with a "What is your country?" field. The only acceptable answers are the names of countries. I have this question in a <SELECT> field but this doesn't stop some kid with nothing better to do from making their own form and having it submit to the controller. They could make their own list of fake countries like "Boogerland" or anything else stupid like that.

    I'm thinking I would have the country list in the database or an XML file, and then they would go in an array. What would happen after that, though, I have no idea


    Also, if anybody wonders, CodeIgniter is getting easier and easier. I'm starting to feel like I know what the heck is going on...most of the time anyway. Hehe

    .
    Last edited by evenstar7139; 08-26-2012 at 05:14 PM.
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles