Page 1 of 1

Custom php_value not working

PostPosted: 29. May 2010 01:05
by RiRL
I have set a custom php_value in the apache configuration, but when I call ini_get() from php, the value does not appear
Apache vhosts has
<VirtualHost *:80>
ServerName foo
DocumentRoot "c:\xampp\app1"
<Directory "c:\xampp\htdocs\app1">
AllowOverride All
Options All
php_value include_path ".;C:\xampp\php\pear\;C:\xampp\htdocs;C:\xampp\htdocs\app1;C:\xampp\htdocs\pcweb\app1\class"
php_value bar_name "bar_none"
</Directory>
<Directory "c:\xampp\htdocs\app2">
AllowOverride All
Options All
php_value include_path ".;C:\xampp\php\pear\;C:\xampp\htdocs;C:\xampp\htdocs\app2;C:\xampp\htdocs\app2\class"
php_value bar_name "ou_et_le_bar_jon"
</Directory>
</VirtualHost>

I am expecting, the bar_name to have the corresponding value....in php code, as follows:
<?php
echo nl2br("bar_name has value ini_get("bar_name"). \n");
?>
show either bar_name (directory context for app1) or ou_et_le_bar_jon (directory context for app2).

It prints
bar_name has value .

(meaning the php_value is not be dealt with properly or I have not done it right).
I can use ini_get("include_path") to get the include path, however.

Any suggestions? :?:

Re: Custom php_value not working

PostPosted: 29. May 2010 03:40
by JonB
just a question:

are we talking about a script that 'should be common' to both of those values?

or are we talking about two scripts that each run inside their respective vhost?

:?:

Re: Custom php_value not working

PostPosted: 01. June 2010 21:53
by RiRL
Thanks Jon,
I am not sure I understand your question, but this I'll try and respond as best I can.

I am trying to be able to obtain an unique value for the bar_name 'property' depending on the respective vhost.
So if the URL is http://foo/app1, then I would like to have ini_get("bar_name") return "bar_none"
So if the URL is http://foo/app2, then I would like to have ini_get("bar_name") return "ou_et_le_bar_jon".

What this will allow me to do is "adapt" the functionality or branding (icons or things) based on the invocation context.
This is going to be used to perform a lookup in some external source. I just need to be able to the get the key value that
varies (somehow) by context.


An alternative solution is too key-off the URL, something like the following:

Given http://foo/app1 index off app1
Given http://foo/app2 index off app2

So I could also use a function like:

function get_app_name($url) {
// input url: => http://foo/app1
// output app: => app1
// HOW? to be determined? Without assuming anything about the form of the URL...
return($app);
}
Not quite sure how to do it. This latter one is probably better since I would not have to mess with the vhosts (for this functionality anyway).

Re: Custom php_value not working

PostPosted: 01. June 2010 23:32
by JonB
Ok
-
You DO realize that VirtualHosts don't 'see' each other, right? They are two separate processes, and have no shared namespace. The fact that they may indeed be in the same domain is pure co-incidence. ISP's use them to carve up servers into neat little chunks, right? (IIS has a similar construct) You would't want your neighbor's processes peering into your memory space?

That is NOT what is shown here:

So if the URL is http://foo/app1, then I would like to have ini_get("bar_name") return "bar_none"
So if the URL is http://foo/app2, then I would like to have ini_get("bar_name") return "ou_et_le_bar_jon".

presumably 'foo' defines the host, and because /app1 and /app2 are to the right of 'foo', they represent elements of 'foo' -- i.e. they can't be in different vhosts. The presumption is that 'foo' has the landing page or governs the applications.

I have done my best to explain a tricky concept, I hope this is clearer. :shock:

Good Luck

:)

There are ways on the client side to maneuver across domains. typically with AJAX.
found one:http://www.phpfour.com/blog/2008/03/cross-domain-ajax-using-php/

Cross-domain scripting in NOT a 'best practise'.

Re: Custom php_value not working

PostPosted: 28. September 2010 06:36
by RiRL
This doesn't have anything to do with something as exotic that.

What I want to do is to provide a value that gets passed thru an invocation content by PHP itself, so I can pick it up
in some PHP code, and load resources from a property file.

If you are at all familiar with OO frameworks and inversion of control, it may help understand what I was trying
to do. I was just trying to provide a context for performing dependency injection of PHP code and resources for factory like objects
(and other things) kept in XML and various other formats. I wanted to be able to define an IOC container and use it in PHP.

I never could get this work using the PHP values mechanism. I ended up looking at the URL and adding logic to parse out the "application name"
from it (this took me about 2 days to figure out) on the main PHP page. I then use this to load properties
from the appropriate section of an external PHP ini file.

http://localhost/foo/index.php => by the above logic produces (foo) which is this used to read in a section of properties (some of which
contain XML documents for declaring and binding objects and methods and data) into my application framework. This property file is located outside
the HTDOCS directory (c:\xampp\ioc).

Thanks for the response, however.

Re: Custom php_value not working

PostPosted: 28. September 2010 10:10
by Nobbie
What is your question now? Where is your problem?