Questions tagged [require-once]

The PHP require_once function

The PHP require_once function.

In contrast to require this function only includes the referred file if it has not been included before.

Use this tag only for questions that directly ask about require_once usage. Do not use this tag if your code contains require_once but you have no reason to believe that require_once is directly related to the issue you are asking about.

409 questions
7
votes
7 answers

PHP absolute path in requireonce

I'm using a simple pre-made authorisation tool to secure my site. The tool requires this line of code to be applied to the top of every .php page. Auth.php lives on the root level. protectme(); ?> I need to be…
fitzilla
  • 915
  • 1
  • 9
  • 11
7
votes
1 answer

Using a constant in require_once

I'm using the following to define root while in development: define('LOCAL_URL', 'http://localhost/~xampp/Mysite'); define('REMOTE_URL', 'http://example.com'); define('DEV_VERSION', true); if(DEV_VERSION) define('URL', LOCAL_URL); else …
circey
  • 2,032
  • 6
  • 35
  • 51
7
votes
5 answers

Is there a way to find out which FILE used require_once?

Let's say I have the following situation: File1.php: File2.php: init.php: I know this is a…
iosifv
  • 1,153
  • 1
  • 10
  • 26
7
votes
4 answers

Include, require & require_once

Today I've tried to include file that returns object. I always use require_once, however now I've noticed weird behavior of it. File main.php $lang = false; $lang->name = "eng"; $lang->author = "Misiur"; $lang->text = "Text is…
Misiur
  • 5,019
  • 8
  • 38
  • 54
7
votes
4 answers

What is the best way to include PHP libraries when using static factory pattern?

I have several static factory patterns in my PHP library. However, memory footprint is getting out of hand and we want to reduce the number of files required during execution time. Here is an example of where we are…
thesmart
  • 2,993
  • 2
  • 31
  • 34
7
votes
11 answers

what's wrong with my require_once path?

I've switched my files over from a local environment to my vps and now my facebook notification isn't working even thought I'm pretty sure I've updated all the paths correctly. I've tried writing the require path numerous ways. I'm doing a "$.post"…
Spilot
  • 1,495
  • 8
  • 29
  • 55
7
votes
7 answers

require_once with subfolders

I have Folder Home with two subfolders like the following +Home +include - membersite_config.php +iDiscover -index.php in index.php I added the require_once script to access membersite_config.php…
Mariam
  • 429
  • 2
  • 7
  • 13
7
votes
3 answers

php require_once path difference between windows and linux

I have a file located in my CakePHP root folder placed under a folder named cron. Path is: c:/wamp/www/project/cron/daily.php This file requires another file placed inside vendor folder of cake structure, like…
Ivin
  • 4,435
  • 8
  • 46
  • 65
6
votes
4 answers

PHP Require and Include GET

I would like to require a file but also pass GET variables through the url, but when I write: I get a fatal error. How would I accomplish this functionality in a different way, such that I…
rolling_codes
  • 15,174
  • 22
  • 76
  • 112
6
votes
3 answers

how to exclude a file after including it in php?

After we add a file inside Myfile.php with: require_once 'abc.php'; or include_once 'abc.php'; How we will remove the file? Or how to stop the abc.php file content being accessed after a certain block of code?
user1638279
  • 523
  • 2
  • 12
  • 26
6
votes
2 answers

what is the purpose of require_once dirname(__FILE__) ...?

I am using a php library which has this code: require_once dirname(__FILE__) . '/config.php'; From what I've read, dirname(__FILE__) points to the current directory. So wouldn't it be easier to just write require_once 'config.php';? My only guess…
Leo Galleguillos
  • 2,429
  • 3
  • 25
  • 43
6
votes
1 answer

PHP Doctrine Beginner: Doctrine\ORM\Tools\Setup not found

im a beginner with doctrine. I just installed pear + doctrine 2.3.3 and want to test it. to test doctrine i wrote a class named "person" /** * @Entity */ class person { /** @Id @Column(type="integer") @GeneratedValue * */ private $id; …
Laokoon
  • 1,241
  • 4
  • 24
  • 47
5
votes
4 answers

PHP Check If require_once() Content Is Empty

I am working on a PHP script which involves me including several external PHP scripts via the "require_once()" method. I would like to know if there is a way for the master script (the one including the others) to tell whether or not the processed…
Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
5
votes
3 answers

Importing PHP code in Joomla Component development

Can't figure out how to import php files into my joomla component- all of these fail: require_once('code.php'); require_once(dirname(FILE).DS.'code.php'); require_once(JPATH_COMPONENT.DS.'code.php' ); Any ideas? thanks
Yarin
  • 173,523
  • 149
  • 402
  • 512
5
votes
5 answers

Split PHP code of a module into separated include files

I have a block of code that I need to use in so many places of my app. Example: $count_device = VSE::count_device($cpe_mac); $c_devices = $count_device['Count_of_devices']; $c_active = $count_device['Count_of_active']; $c_inactive =…
code-8
  • 54,650
  • 106
  • 352
  • 604
1
2
3
27 28