On my development computer, I have virtual named host set up, like www.site1.lab.
When I upload those to my web site for customer review under
mywebsite.com/clients/site1/
it throws some of the source file references off and it does not work
properly.
My references are like:
require_once($_SERVER['DOCUMENT_ROOT']."/utility/top.php");
Obviously those will not work since $_SERVER['DOCUMENT_ROOT'] references
mywebsite.com.
Is there anything I can do in apache.conf for a virtual directory that would
make it so when I upload a site for customer review, I don't have to change
the source references? 17 1670
Paul wrote:
On my development computer, I have virtual named host set up, like www.site1.lab.
When I upload those to my web site for customer review under
mywebsite.com/clients/site1/
it throws some of the source file references off and it does not work
properly.
My references are like:
require_once($_SERVER['DOCUMENT_ROOT']."/utility/top.php");
Obviously those will not work since $_SERVER['DOCUMENT_ROOT']
references mywebsite.com.
Is there anything I can do in apache.conf for a virtual directory
that would make it so when I upload a site for customer review, I
don't have to change the source references?
As long as you've really got a virtualhost set, and set the DocmentRoot for
that domain explicitly, is should have the right $_SERVER['DOCUMENT_ROOT'].
Relevant settings:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/path/to/test/docroot"
ServerName test.localhost
</VirtualHost>
server.php:
<?php
echo $_SERVER['DOCUMENT_ROOT'];
?>
Which correctly results in : /path/to/test/docroot
--
Rik Wasmus
Paul wrote:
require_once($_SERVER['DOCUMENT_ROOT']."/utility/top.php");
That's not a great way of referencing included files. It makes it
difficult to move your site around.
Try instead creating a directory called "includes", and putting all your
included files into there, like:
includes/search_functions.php
includes/database_functions.php
includes/utility/top.php
includes/utility/bottom.php
includes/utility/left.php
includes/utility/right.php
Now, when you need to refer to them, use:
require_once 'utility/top.php';
Note here that we've not specified the full path for the file, not even a
normal relative path -- we've specified where it is RELATIVE TO THE
"includes" DIRECTORY, not relative to where we are now.
Now in your .htaccess file, you can set:
php_value includes_path /full/path/to/includes/
So when PHP sees a 'include' or 'require' statement, it will search
through the path(s) in the includes_path setting and look for
/full/path/to/includes/utility/top.php.
Yay
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Toby Inkster wrote:
Paul wrote:
>require_once($_SERVER['DOCUMENT_ROOT']."/utility/top.php");
That's not a great way of referencing included files. It makes it
difficult to move your site around.
Try instead creating a directory called "includes", and putting all your
included files into there, like:
includes/search_functions.php
includes/database_functions.php
includes/utility/top.php
includes/utility/bottom.php
includes/utility/left.php
includes/utility/right.php
Now, when you need to refer to them, use:
require_once 'utility/top.php';
Note here that we've not specified the full path for the file, not even a
normal relative path -- we've specified where it is RELATIVE TO THE
"includes" DIRECTORY, not relative to where we are now.
Now in your .htaccess file, you can set:
php_value includes_path /full/path/to/includes/
So when PHP sees a 'include' or 'require' statement, it will search
through the path(s) in the includes_path setting and look for
/full/path/to/includes/utility/top.php.
Yay
Actually, that's the BEST WAY to reference your files.
$_SERVER['DOCUMENT_ROOT'] will ALWAYS contain the absolute path to the
root directory of your site, no matter where it is. You need to make no
changes to any files when referencing this way.
Then you don't need any entry in your .htaccess file (which even Apache
recommends against using), you don't have to worry about setting it up
or anything else. Everything works automatically.
I use this all the time in my sites. I can move them between different
test machines (both local and on the internet), the final site - whatever.
I've even moved complete sites from one provider to another. All that
was necessary was to upload and go.
And BTW - it works in IIS also, which doesn't have a .htaccess file.
Works great, in fact.
Use the server-provided values where you can. That's what they're there
for.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Jerry Stuckle wrote:
$_SERVER['DOCUMENT_ROOT'] will ALWAYS contain the absolute path to the
root directory of your site, no matter where it is. You need to make no
changes to any files when referencing this way.
Makes it tricky to move your PHP around *within* your document root
though. I try to make my code run equally well rooted in "/somedir/" as it
does in "/".
Putting everything in an 'includes' directory and then specifying the
location of the files in include_path allows you to easily move the
includes anywhere (including outside the document root altogether, which
is often desirable from a security POV) without making any changes to your
scripts at all.
Then you don't need any entry in your .htaccess file (which even Apache
recommends against using), you don't have to worry about setting it up
or anything else. Everything works automatically.
Better to use "httpd.conf" or "php.ini" for such settings, but not
everyone is able to. I tend to use ".htaccess" for testing and then
migrate to "httpd.conf" once I'm sure.
And BTW - it works in IIS also, which doesn't have a .htaccess file.
Works great, in fact.
As does "include_path" -- you just need to set it in php.ini.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Toby Inkster wrote:
Jerry Stuckle wrote:
>$_SERVER['DOCUMENT_ROOT'] will ALWAYS contain the absolute path to the root directory of your site, no matter where it is. You need to make no changes to any files when referencing this way.
Makes it tricky to move your PHP around *within* your document root
though. I try to make my code run equally well rooted in "/somedir/" as it
does in "/".
Sure. But I almost never do that. And if I do, I can quickly do a
search/replace for the file path. On a 3K+ file site it takes less than
a minute to replace all of the references.
Putting everything in an 'includes' directory and then specifying the
location of the files in include_path allows you to easily move the
includes anywhere (including outside the document root altogether, which
is often desirable from a security POV) without making any changes to your
scripts at all.
Sure - if you're on Apache, if you have .htaccess, if your host allows
PHP changes to .htaccess...
And files can be outside of the document root with this means, also - i.e.
$_SERVER['DOCUMENT_ROOT'] . '/../passwords.txt'
would be the file 'passwords.txt' one level below the document root.
And again - search/replace changes the scripts just fine. Use the right
tools and you don't need gimmicks.
>Then you don't need any entry in your .htaccess file (which even Apache recommends against using), you don't have to worry about setting it up or anything else. Everything works automatically.
Better to use "httpd.conf" or "php.ini" for such settings, but not
everyone is able to. I tend to use ".htaccess" for testing and then
migrate to "httpd.conf" once I'm sure.
Again - what if you're on an IIS system? No .htaccess. What if your
hosting company has restricted you so that PHP cannot load values from
..htaccess? I've found several who do.
>And BTW - it works in IIS also, which doesn't have a .htaccess file. Works great, in fact.
As does "include_path" -- you just need to set it in php.ini.
Which is impossible on a shared host. Not everyone has access to or
needs a dedicated server or a vps.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
That works but here's the issue. I develop locally using virtual host like www.client1site.com. When I want my client to see the progress, I upload
to: www.mysite.com/clients/client1/
So you can see that by referencing:
require_once($_SERVER['DOCUMENT_ROOT']."/utility/top.php");
take the reference to mysite.com/utility/, where instead I want it to go to
mysite.com/clients/client1/utility
Does that make better sense?
I am just looking for a way where I don't have to change all my references
when I upload it for client review, BEFORE uploading it to it's final host.
Paul wrote:
That works but here's the issue. I develop locally using virtual host like www.client1site.com. When I want my client to see the progress, I upload
to:www.mysite.com/clients/client1/
So you can see that by referencing:
require_once($_SERVER['DOCUMENT_ROOT']."/utility/top.php");
take the reference to mysite.com/utility/, where instead I want it to go to
mysite.com/clients/client1/utility
Does that make better sense?
I am just looking for a way where I don't have to change all my references
when I upload it for client review, BEFORE uploading it to it's final host.
On your "DEV" machine create a file called const_path.php (or something
like that) on a fixed location.
Similar to your "DEPLOYMENT" machine,
create another file (with same name, with same location relative to
$_SERVER['DOCUMENT_ROOT'].
On that file, you define your path constants.
On your "DEV" machine.... it will be: define('CONST_PATH_UTILITY',
$_SERVER['DOCUMENT_ROOT'].'/utility');
On your "DEPLOYMENT" machine ... define('CONST_PATH_UTILITY',
$_SERVER['DOCUMENT_ROOT'].'/clients/client1/utility');
On your page, you need to include the file:
require_once($_SERVER['DOCUMENT_ROOT'].'/const_path.php');
Then you include your utility file:
require_once(CONST_PATH_UTILITY . '/top.php');
Make sure you don't overwrite the two different const_path.php between
"DEV" and "DEPLOYMENT" server
--- OR ---
you can always use relative path :)
Hendri Kurniawan
Paul wrote:
That works but here's the issue. I develop locally using virtual host like www.client1site.com. When I want my client to see the progress, I upload
to:www.mysite.com/clients/client1/
So you can see that by referencing:
require_once($_SERVER['DOCUMENT_ROOT']."/utility/top.php");
take the reference to mysite.com/utility/, where instead I want it to go to
mysite.com/clients/client1/utility
Does that make better sense?
I am just looking for a way where I don't have to change all my references
when I upload it for client review, BEFORE uploading it to it's final host.
I don't understand your problem.
Let's say your local machine path the the file is
/var/http/clients/client1/utility/top.php
So, just have a virtual host on your local machine which points to
/var/http/clients/client1. Another virtual host will point at a
different directory.
I have about a dozen different virtual hosts on my development machine
right now, each pointing to a different directory. And the files on
every one have the same path relative to their document root that the
specific client has.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
..oO(Jerry Stuckle)
>Again - what if you're on an IIS system? No .htaccess. What if your hosting company has restricted you so that PHP cannot load values from .htaccess? I've found several who do.
Change the host? Why should I stay with a company that doesn't provide
the tools I need?
>As does "include_path" -- you just need to set it in php.ini.
Which is impossible on a shared host.
Depends. I'm on a shared host and can use my own php.ini.
Micha
Michael Fesser wrote:
.oO(Jerry Stuckle)
>Again - what if you're on an IIS system? No .htaccess. What if your hosting company has restricted you so that PHP cannot load values from .htaccess? I've found several who do.
Change the host? Why should I stay with a company that doesn't provide
the tools I need?
>>As does "include_path" -- you just need to set it in php.ini.
Which is impossible on a shared host.
Depends. I'm on a shared host and can use my own php.ini.
Micha
Not really,
If they're using the CGI version of PHP (instead of the Apache
extension), you can use a subset of the php.ini in your directory. But
unless they have no concerns about security (or don't understand
security), you won't be able to put all the possible options in it. And
what they allow or disallow varies from one host to another.
And if you do have all options available I'd switch hosts - FAST.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
..oO(Jerry Stuckle)
>Michael Fesser wrote:
>> Depends. I'm on a shared host and can use my own php.ini.
Not really,
If they're using the CGI version of PHP (instead of the Apache extension), you can use a subset of the php.ini in your directory. But unless they have no concerns about security (or don't understand security), you won't be able to put all the possible options in it.
True. But it's more than enough. Additionally many of the most-used
directives are PHP_INI_ALL, so they can be set everywhere.
Micha
Jerry Stuckle wrote:
If they're using the CGI version of PHP (instead of the Apache
extension), you can use a subset of the php.ini in your directory. But
unless they have no concerns about security (or don't understand
security), you won't be able to put all the possible options in it. And
what they allow or disallow varies from one host to another.
And if you do have all options available I'd switch hosts - FAST.
So that's what's going on!
I have a PHP.ini file, too.
I was wondering how they can do that, and still keep their
servers from blowing up.
Michael Fesser wrote:
.oO(Jerry Stuckle)
>Michael Fesser wrote:
>>Depends. I'm on a shared host and can use my own php.ini.
Not really,
If they're using the CGI version of PHP (instead of the Apache extension), you can use a subset of the php.ini in your directory. But unless they have no concerns about security (or don't understand security), you won't be able to put all the possible options in it.
True. But it's more than enough. Additionally many of the most-used
directives are PHP_INI_ALL, so they can be set everywhere.
Micha
Maybe it's more than enough. Maybe not. It all depends on what they
allow you to set.
And if you ever change hosts to someone using the Apache extension,
you'll be SOL. It's even worse if you change to a Windows host.
The bottom line is - this doesn't work on every system. The
$_SERVER['DOCUMENT_ROOT'] does.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
..oO(Jerry Stuckle)
>And if you ever change hosts to someone using the Apache extension, you'll be SOL. It's even worse if you change to a Windows host.
Why should I? My own sites and the sites I maintain are hosted on
servers carefully chosen by me. There's no reason to change.
Micha
Michael Fesser wrote:
.oO(Jerry Stuckle)
>And if you ever change hosts to someone using the Apache extension, you'll be SOL. It's even worse if you change to a Windows host.
Why should I? My own sites and the sites I maintain are hosted on
servers carefully chosen by me. There's no reason to change.
Micha
And I've heard that one so many times before. The last time just a few
months ago with a company who had been an excellent provider for years.
Companies change. Management changes. Companies get new owners. And
companies go out of business.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
As I am not having much experience, I don't know if the following will
result any security vulnerability, or may be effect at other part of
the code causing unexpected results internally.
/* concat path */
$_SERVER['DOCUMENT_ROOT'] .= "/clients/site1";
But for temporary purpose, can this be used at the top of every page/or
any common page that is being included by all other files.
What I generally do is,
(in config file)
define('APP_DIR', '/any/path/if/present/');
define('APP_FULL_URL', 'http://'.$_SERVER["HTTP_HOST"].APP_DIR);
and use "APP_FULL_URL" to include files, etc.
Other is I define a variable $basepath at the top of every page, that
is relative to the directory that has main index file for the site.
/
all files have $basepath="./";
/dir1/
/dir2/
all files have $basepath="./../";
/dir1/subdir1/
/dir2/subdir1/
all files have $basepath="./../../";
defined at top of page.
And $basepath is used for including all other files.
May not be good way to do, but has been working fine for all projects
till now.
Paul wrote:
On my development computer, I have virtual named host set up, like www.site1.lab.
When I upload those to my web site for customer review under
mywebsite.com/clients/site1/
it throws some of the source file references off and it does not work
properly.
My references are like:
require_once($_SERVER['DOCUMENT_ROOT']."/utility/top.php");
Obviously those will not work since $_SERVER['DOCUMENT_ROOT'] references
mywebsite.com.
Is there anything I can do in apache.conf for a virtual directory that would
make it so when I upload a site for customer review, I don't have to change
the source references?
ALl good thoughts - I'll give them a try - many thanks This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: andy |
last post by:
Hi,
I'm trying to get mod_python working on my web server, but I'm running
into problems, possibly due to having virtual hosts configured.
I'm no apache guru (newbie is more accurate!) so I...
|
by: nick |
last post by:
I have a problem and I've been using a cheezy work around and was
wondering if anyone else out there has a better solution.
The problem:
Let's say I have a web application appA. Locally, I set...
|
by: B Letts |
last post by:
Hi -
I'm currently using the FileUpload control to allow people to upload
files to my website. This all works fine, as long as I'm going to a
physical path on my server.
However, I need to...
|
by: David Lozzi |
last post by:
Howdy,
I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders!
Now I am making a public function that will take the...
|
by: antonyliu2002 |
last post by:
I've set up the virtual smtp server on my IIS 5.1 like so:
1. Assign IP address to "All Unassigned", and listen to port 25.
2. Access Connection granted to "127.0.0.1".
3. Relay only allow...
|
by: Wayne Smith |
last post by:
I've come up against a major headache that I can't seem to find a solution
for but I'm sure there must be a workaround and I would really be grateful
of any help.
I'm currently building a web...
|
by: Marko Vuksanovic |
last post by:
I am trying to cause the uplaod button, id="Upload",when clicked, to exectue the onClick event for Button1, id="Button1".
<asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>...
|
by: Buddy Home |
last post by:
Hello,
I'm trying to upload a file programatically and occasionally I get the
following error message.
Unable to write data to the transport connection: An established connection
was aborted...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |