Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] index.php if base url redirect codeigniter
#1

[eluser]riwakawd[/eluser]
On my index.php in codeigniter I am trying to find the best way to make the BASE_URL redirect to APPPATH . modules/install/step1.php if it has not done before

What would the best way for it for to work I have tried to !defined header location

How can I make it redirect on the index.php APPPATH . modules/install/step1.php if server has not been to the path set.

Top of the main index.php This code below just makes it easier so user does not have to enter base url.

Code:
<?php

if (isset($_SERVER['HTTP_HOST'])) {

    $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
    $base_url .= '://'. $_SERVER['HTTP_HOST'];
    $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

    } else {

    // Back Up Url
    $base_url = 'http://localhost/';

}

define('BASE_URL', $base_url);

unset($base_url);

Config/config.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = BASE_URL;



/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
#2

[eluser]Tim Brownlaw[/eluser]
Am I guessing correctly that you are wanting to achieve something like...

1. Check that the script has been installed.
If the script has not been installed - then run the installer
else - carry on as usual.



#3

[eluser]riwakawd[/eluser]
[quote author="Tim Brownlaw" date="1405065047"]Am I guessing correctly that you are wanting to achieve something like...

1. Check that the script has been installed.
If the script has not been installed - then run the installer
else - carry on as usual.



[/quote]

Yes some thing like that I use my_loader.php weather it could be put in there or on the index.php just not sure what and were to put it.
#4

[eluser]joergy[/eluser]
I'm using the following function.
/start/fw is a part of the URI to my script, which i consider being unique below my DocumentRoot.
Normally $_SERVER["PHP_SELF"] et. al. are considered as dangerous, but I don't build any output out of it, and I only make use the part of the path in front of my /start/fw (if You don't understand what I'm talking about, simply ignore my last sentence).

Code:
function get_base_url(){
  // find the partial path below DocumentRoot to the XXX folder, including it if present
  // e.a. from /a/path/to/XXX/start/fw... and DocumentRoot = /a/path we get /to/XXX/ as base_url
  $uri = empty($_SERVER["PHP_SELF"]) ? "" : $_SERVER["PHP_SELF"];
  $pos = strpos($uri,"/start/fw");
  if($pos === false) {
   $uri = empty($_SERVER["SCRIPT_NAME"]) ? "" : $_SERVER["SCRIPT_NAME"];
   $pos = strpos($uri,"/start/fw");
   if($pos === false) {
    $uri = empty($_SERVER["REQUEST_URI"]) ? "" : $_SERVER["REQUEST_URI"];
    $pos = strpos($uri,"/start/fw");
    if($pos === false) show_error("FATAL: Can't find fw in helper start_params().");
   }
  }
  return substr($uri,0,$pos)."/";
}
#5

[eluser]CroNiX[/eluser]
After a successful install, you could just create a file like install.dat that is empty at a specific location. Then in your index (I'd actually use a MY_Controller) you can just check to see if the file exists. If so, carry on. If not, redirect to the install controller.
#6

[eluser]CroNiX[/eluser]
Why not just create a route for your install? Then you wouldn't need to do most of that. You could just

Code:
if ( ! file_exists(install.dat))
{
  header('Location: /index.php/the-predefined-route-to-the-install-module');
}




Theme © iAndrew 2016 - Forum software by © MyBB