-2

Im struggling with the basics here and any help is appreciated.

I have an index.php in the main website folder:

www.site.com/index.php

I have a sub folder here with a file I want to include:

www.site.com/book/application/language/english/translations_lang.php

When trying to include the file in my index.php the website fails to load

I have tried this:

<? php include '/book/application/language/english/translations_lang.php'; ?>

When the above failed I also removed the slash at the start, I also tried moving the translations file to the same sirectory as the index file but the site fails to load every time.

The translations file has the following:

<?php defined('BASEPATH') OR exit('No direct script access allowed');
// English
$lang['company_name'] = 'Big Company';

I think i get an idea that its the BASEPATH thats stopping this from being read and causing the failure of the site.

Help

tryer
  • 81
  • 8
  • 1
    "When the above failed" In what way did if fail? What _did_ happen? – Patrick Q Nov 13 '19 at 18:29
  • 2
    First does `index.php` contain `define('BASEPATH', 'something')`? Second remove the first `/` from `/book` – AbraCadaver Nov 13 '19 at 18:30
  • The error is a HTTP 500 (using Chrome). The index file has no define(base) etc in it – tryer Nov 13 '19 at 18:32
  • 1
    Using `/` at the beginning of the path tells PHP to start looking for the file from the system root, not the site root. You need to use `$_SERVER['DOCUMENT_ROOT']` or BASEPATH to traverse the actual file. – aynber Nov 13 '19 at 18:32
  • A 500 error is a generic error message and covers pretty much every single thing that can go wrong with a PHP script. Check your server error logs to find out the exact error message. – aynber Nov 13 '19 at 18:33
  • If you are getting a 500 status, then you need to check your error logs for the actual error message. – Patrick Q Nov 13 '19 at 18:33
  • Thank you for pointing me towards the logs. This is the error: 13-Nov-2019 18:31:32 UTC] PHP Parse error: syntax error, unexpected 'include' (T_INCLUDE) – tryer Nov 13 '19 at 18:35
  • Not sure if this is throwing the error, but ` php` should not have a space in it. – aynber Nov 13 '19 at 18:36
  • Possible duplicate of [PHP parse/syntax errors; and how to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – aynber Nov 13 '19 at 18:36
  • I took the space out of the ? PHP - New error of: No direct script access allowed – tryer Nov 13 '19 at 18:38
  • So now you just need to define the constant (in index.php) before checking for it (in translations_lang.php) – Patrick Q Nov 13 '19 at 18:46
  • This is where Iim getting a bit lost and confused. Define it where exactly – tryer Nov 13 '19 at 18:55
  • 1
    It's a codeigniter constant, so make sure that the file that you're using to include `translations_lang.php` is also using the Codeigniter framework – aynber Nov 13 '19 at 19:08
  • 1
    I think you mix up things here, to take advantage of Codeigniters language class: https://codeigniter.com/user_guide/libraries/language.html – Vickel Nov 13 '19 at 19:13
  • In the constants.php I have just added this: define('PRIV_INDEX', 'index'); But theres surely something else I need to do for index.php to pick up on this – tryer Nov 13 '19 at 19:18
  • Any further advice? Ive checked the config.php and it holds a defined('BASEPATH') in it. Not sure what I need to do here – tryer Nov 14 '19 at 09:28

1 Answers1

0

Please use this

<?php include dirname(__FILE__) . '/book/application/language/english/translations_lang.php'; ?>
Liki Crus
  • 1,901
  • 5
  • 16
  • 27
  • Didn't work unfortunately. My file is outside of code igniter. Is it still possible to do? – tryer Nov 14 '19 at 17:36
  • @tryer I'm confused. You tagged this question with _3_ codeigniter tags. But now you are saying that this code is _not_ using codeigniter? – Patrick Q Nov 14 '19 at 19:47
  • @tryer, translations_lang.php is a PHP file to define the array variables. So if you include it, you can use the data in this file anywhere. please include this code block on your index.php define('BASEPATH', dirname(__FILE__)); – Liki Crus Nov 14 '19 at 22:22