Re: [PHP] Invoking functions stored in a separate directory?
On Sat, 22 Aug 2009 20:37:17 +0930, robl...@aapt.net.au (David Robley) wrote: >Clancy wrote: > >> $ok = include (HOST_PATH.'/Halla.php'); > >Because you are assigning the result of the include to a variable. Try > >include (HOST_PATH.'/Halla.php'); > >and it will work as you expect. And similarly for > >define ('HOST_PATH','../Engine'); Thanks. But no; that's not the answer. 'Include', like any other function, returns a result; true if the operation was successful, and false if it failed. I was using this to verify that the 'include' operation had been successful. The more I thought about it last night, the more dissatisfied I became with the notions that 'include' could work differently in different circumstances, and also that defining a path could alter the way it worked. I did some more tests this morning, and eventually established that my confusion was the result of two different effects. The first was that I find the PHP syntax rather picky, and I rely on error messages to alert me to my frequent errors, but apparently all error messages are turned off on the remote system, and if anything is wrong all I get is a blank screen. The second is that although I use Dreamweaver as an editor, and it has moderately good colour coding which indicate most errors, I am partially red green colour blind and tend not to notice the erroneous colours. I repeated my tests this morning and eventually managed to establish that i. there is no difference in the behaviour of include between the local and remote systems, and ii. contrary to Arno's advice, include ../Engine/Main_prog.php; works just the same as include ENGINEPATH."Main_prog.php"; So now I can get on with uploading my program! Thanks, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Invoking functions stored in a separate directory?
Clancy wrote: > $ok = include (HOST_PATH.'/Halla.php'); Because you are assigning the result of the include to a variable. Try include (HOST_PATH.'/Halla.php'); and it will work as you expect. And similarly for define ('HOST_PATH','../Engine'); Cheers -- David Robley Dynamic linking error: Your mistake is now everywhere. Today is Prickle-Prickle, the 15th day of Bureaucracy in the YOLD 3175. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Invoking functions stored in a separate directory?
On Fri, 21 Aug 2009 15:16:11 +0200, ak...@telkomsa.net ("Arno Kuhl") wrote: >-Original Message- >From: Clancy [mailto:clanc...@cybec.com.au] >Sent: 21 August 2009 01:26 PM >To: php-general@lists.php.net >Subject: [PHP] Invoking functions stored in a separate directory? > >I am developing an idea for a website engine which can be shared between >several different websites. Each website would have its own directory under >a common root directory, and the engine would be in a separate directory >Engine: > >Root >Website_1.com, Website_2.com, Engine > >The website directories would each contain the design data for that website, >consisting basically of a mixture of text files and images. The various >pages would be loaded by loading index.php from the website root directory, >and specifying a number of parameters e.g. > >http://www.corybas.com/index.php?path=Holidays&level=0&item=0 > >I have the minimum amount of code in index.php -- just enough to set some >parameters to identify the website, and then include >../Engine/Main_prog.php. This in turn can include any of a large number of >other include files to carry out particular functions. . > >Using include ../Engine/Main_prog.php won't work for you in a production >environment. You need to create a path.php file that defines the absolute >path to the engine for each website, and include it at the top of your >website script. Then you can do something like: > > include ENGINEPATH."Main_prog.php"; Thank you very much for this. It has at last provided the clue I was looking for, and after far too long I have got a trivially simple demonstration working. One complication I hadn't anticipated is that apparently I can only access functions in the include file, but cannot execute any code in it. Thus when Halla.php read: Eng_test_'.__LINE__.' Hallejuha!! : '; ?> and I included it: $ok = define ('HOST_PATH','../Engine'); $ok = include (HOST_PATH.'/Halla.php'); nothing happened. When Halla.php read: Eng_test_'.__LINE__.' Hallejuha!! : '.$i.''; return $i; } ?> and I included it: $ok = define ('HOST_PATH','../Engine'); $ok = include (HOST_PATH.'/Halla.php'); $ok = halla (7); echo ' Returned '.$ok''; it did work. I presume that this explains your next comment, in that I am neither reading nor executing the code in the Include, so permissions don't come into it. >You shouldn't really have permission problems as long as your website and >engine are on the same server. ... >One other advantage it will give you for your particualr design is that you >can have multiple engines per server (e.g. Engine1, Engine2, etc) so that >you can bring one engine down for upgrade while still keeping sites running >on the other engines. Yes; I have got already got all that working. Now I JUST have to convert my main program into one big function! Will I still be able to access $_GET & $_POST variables, and set up session variables from inside this function? I guess I can declare them all GLOBAL? Thanks, again, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Invoking functions stored in a separate directory?
-Original Message- From: Clancy [mailto:clanc...@cybec.com.au] Sent: 21 August 2009 01:26 PM To: php-general@lists.php.net Subject: [PHP] Invoking functions stored in a separate directory? I am developing an idea for a website engine which can be shared between several different websites. Each website would have its own directory under a common root directory, and the engine would be in a separate directory Engine: Root Website_1.com, Website_2.com, Engine The website directories would each contain the design data for that website, consisting basically of a mixture of text files and images. The various pages would be loaded by loading index.php from the website root directory, and specifying a number of parameters e.g. http://www.corybas.com/index.php?path=Holidays&level=0&item=0 I have the minimum amount of code in index.php -- just enough to set some parameters to identify the website, and then include ../Engine/Main_prog.php. This in turn can include any of a large number of other include files to carry out particular functions. I have the prototype working nicely on my PC, and on a stand-alone basis on a server, but now I am trying to upload the multi-website version to a public host, and am encountering a number of problems, mainly because I have never done any serious work with UNIX, and the host support staff don't understand what I am trying to do. The problems mainly relate to setting permissions to allow the website to access the engine code. I only have a rough idea of how the permissions work, but I think that to include engine code the website has to have read and execute rights to it, and I also think that so far as the engine is concerned the website will count as 'other'. (I can easily arrange that all temporary files are written in the website directory.) I suspect that rather than including the engine code in index.php, it would be better to call functions in it, so that the website only required 'execute' rights, but I don't know of any way to do this without having anything running permanently on the server. Can anyone suggest how it can be done? - Using include ../Engine/Main_prog.php won't work for you in a production environment. You need to create a path.php file that defines the absolute path to the engine for each website, and include it at the top of your website script. Then you can do something like: include ENGINEPATH."Main_prog.php"; You can have different path files, one for dev and one for live, that allows you to use the same scripts for both environments and just use the appropriate path definition script. E.g. Windows path.php define('ENGINEPATH','../Engine/'); Linux path.php define('ENGINEPATH','/usr/home/Engine/'); You shouldn't really have permission problems as long as your website and engine are on the same server. I do something similar where the bulk of my code is below doc root, and I use path files to find the main system directories. The beauty of it is you can change your mind about directory structures, and just change the path file definitions without making any changes in the application code (my path file defines about 20 directories). It also lets you do dev on a Windows pc and deploy on a *nix box without any problems - just use a different path file for each. One other advantage it will give you for your particualr design is that you can have multiple engines per server (e.g. Engine1, Engine2, etc) so that you can bring one engine down for upgrade while still keeping sites running on the other engines. Cheers Arno -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Invoking functions stored in a separate directory?
I am developing an idea for a website engine which can be shared between several different websites. Each website would have its own directory under a common root directory, and the engine would be in a separate directory Engine: Root Website_1.com, Website_2.com, Engine The website directories would each contain the design data for that website, consisting basically of a mixture of text files and images. The various pages would be loaded by loading index.php from the website root directory, and specifying a number of parameters e.g. http://www.corybas.com/index.php?path=Holidays&level=0&item=0 I have the minimum amount of code in index.php -- just enough to set some parameters to identify the website, and then include ../Engine/Main_prog.php. This in turn can include any of a large number of other include files to carry out particular functions. I have the prototype working nicely on my PC, and on a stand-alone basis on a server, but now I am trying to upload the multi-website version to a public host, and am encountering a number of problems, mainly because I have never done any serious work with UNIX, and the host support staff don't understand what I am trying to do. The problems mainly relate to setting permissions to allow the website to access the engine code. I only have a rough idea of how the permissions work, but I think that to include engine code the website has to have read and execute rights to it, and I also think that so far as the engine is concerned the website will count as 'other'. (I can easily arrange that all temporary files are written in the website directory.) I suspect that rather than including the engine code in index.php, it would be better to call functions in it, so that the website only required 'execute' rights, but I don't know of any way to do this without having anything running permanently on the server. Can anyone suggest how it can be done? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php