Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jan 2013
    Location
    Australia
    Posts
    118
    Thanks
    22
    Thanked 0 Times in 0 Posts

    If (!define) not working Codeigniter

    Hello. I am having trouble with my main index.php

    I have a install folder for my front end users. If user is installed copy for the first time it should go to the install index.php

    Other wise it goes to the main website page and user has full access. So does not have to go through install process again.

    The code below is not working once the user has reached step_4 should be able to view website.

    But currently still gets routed to install index.php

    PHP Code:
    if ( ! define('install/index.php'))
    {
        
    // Make sure we've not already tried this
        
    if (strpos($_SERVER['REQUEST_URI'], '/install/'))
        {
            
    header('Status: 404');
            exit;
        }
        
        
    // Otherwise go to installer
        
    header('Location: '.rtrim($_SERVER['REQUEST_URI'], '/').'/install/');
        exit;

    Founder Of Riwaka Website Designs
    http://www.riwakawebsitedesigns.com

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    What are you trying to perform here? define constructs a constant, and it should not be used as a comparator. Ie:
    PHP Code:
    define('A''a value');

    if (!
    define('A'))
    {
        
    printf("Something broke");
    }

    print 
    A
    Would result in:
    Code:
    <br />
    <b>Warning</b>:  define() expects at least 2 parameters, 1 given in <b>[...][...]</b> on line <b>3</b><br />
    Something brokea value
    What you are doing cannot be used in a constant as the characters are invalid (they must follow variable naming conventions).

    You'll need to use some type of persisting data in order to determine if you should go somewhere. Perhaps you are intending to use something like file_exists?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I was curious about the comparator as well, but I still don't think that's the intention here. Yep, the defined will let you see if a constant is defined, but the constant you've provided cannot possibly exist (through normal means, you can force it).
    I still think there's something else that the op is trying to compare on.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder
    Join Date
    Jan 2013
    Location
    Australia
    Posts
    118
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    I was curious about the comparator as well, but I still don't think that's the intention here. Yep, the defined will let you see if a constant is defined, but the constant you've provided cannot possibly exist (through normal means, you can force it).
    I still think there's something else that the op is trying to compare on.
    Hi Thanks for message. I replaced define with defined but still same issue on codeigniter index.php. I am trying to make it so once user has completed all 4 install/steps that will have access to website.

    I tried it like so

    PHP Code:
    if ( ! defined('install/index.php'))
    {
        
    // Make sure we've not already tried this
        
    if (strpos($_SERVER['REQUEST_URI'], '/install/'))
        {
            
    header('Status: 404');
            exit;
        }
        
        
    // Otherwise go to installer
        
    header('Location: '.rtrim($_SERVER['REQUEST_URI'], '/').'/install/');
        exit;

    Founder Of Riwaka Website Designs
    http://www.riwakawebsitedesigns.com

  • #6
    Regular Coder
    Join Date
    Jan 2013
    Location
    Australia
    Posts
    118
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    I was curious about the comparator as well, but I still don't think that's the intention here. Yep, the defined will let you see if a constant is defined, but the constant you've provided cannot possibly exist (through normal means, you can force it).
    I still think there's something else that the op is trying to compare on.
    I think i realize what I need to do. I need to some how make in my last install/step_4 make a script that can let me have access to main website once install is complete. In my codeigniter controller.
    Founder Of Riwaka Website Designs
    http://www.riwakawebsitedesigns.com

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    Regular Coder
    Join Date
    Jan 2013
    Location
    Australia
    Posts
    118
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Nothing in your post.
    Founder Of Riwaka Website Designs
    http://www.riwakawebsitedesigns.com

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    He's pointing out my previous post that neither define nor defined are what you are looking for, but I'm not sure what you need to do to persist the data. To me, a session would make the most sense as you can store the step you are currently on and retrieve it later to see what was done.
    PHP Code:
    <?php

    session_start
    ();
    if (isset(
    $_SESSION['step']))
    {
        
    $step $_SESSION['step'];
    }
    else
    {
        
    $step 1;
    }
    switch (
    $step)
    {
        case 
    1:
            
    performStep1();
            
    $_SESSION['step'] = 2;
            break;
        case 
    2:
            
    performStep2();
            
    $_SESSION['step'] = 3;
            break;
        
    #. . .
    }
    for example. Track the step in the session so you can see where you left off. This assumes that the same script is responsible for each step.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    riwakawd (05-24-2014)


  •  

    Tags for this Thread

    Posting Permissions

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