Copy link to clipboard
Copied
hello everyone,
need some advice on the best way to do this, not sure if some logic like this is even needed, i may be over thinking it.
First a little background:
I have a clipbucket 2.6 site. works great on remote. when i install with xampp on my personal computer errors being thrown of
Call to undefined method ADODB_mysql::select()
now i found a fix for this on their site, it is to change a line in their code:
require 'adodb/adodb.inc.php';
to something that will reference the file correctly in a local environment. some people suggest
require '/FULL PATH TO/adodb/adodb.inc.php';
but that does not work for me, i get errors of not being able to find file, turns out it only works on wamp or lampp, i use xampp
THIS is what works on my local xampp test server:
require 'C:\xampp\htdocs\videoz\includes\adodb\adodb.inc.php';
NOW MY QUESTION:
require 'C:\xampp\htdocs\videoz\includes\adodb\adodb.inc.php';
will not work on remote to reference the file correctly.
How can i make some logic to decide if a script is being executed on local or remote and include a filepath accordingly?
if file exists?
server root?
suggestions?'
ideas?
is this even the right way to go about this? I cant figure out a way to scructure the include to work with both, i have it disabled to use variables in include statements (whatever its called), ha
any suggestions on how to do this effectively and most importantly safely??
thanks a ton for your attention!
You can do something like this:
if ($_SERVER['SERVER_NAME'] == 'mylittlehost'){
// do this
} else {
// do that
}
. . .and yes, to answer your question, this is a good way to go about this.
An alternate way is to have an include with a set of functions, etc. that is for your local site, and an include of the same name that contains the comparable functions for the remote site, but the day may come when you accidently upload your local version to the remote, causing the remote site to break.
Copy link to clipboard
Copied
You can do something like this:
if ($_SERVER['SERVER_NAME'] == 'mylittlehost'){
// do this
} else {
// do that
}
. . .and yes, to answer your question, this is a good way to go about this.
An alternate way is to have an include with a set of functions, etc. that is for your local site, and an include of the same name that contains the comparable functions for the remote site, but the day may come when you accidently upload your local version to the remote, causing the remote site to break.
Copy link to clipboard
Copied
Why not forget the whole if local do this, if server do that and just use one line of code that references the file you have uploaded on your server?
require 'http://yoursite.com/path/to/file/online/adodb.inc.php';
best,
Shocker ![]()
Copy link to clipboard
Copied
Shocker, the answer is that we generally want to have our local and remote systems as identical as possible, and also portable. Having to remember or account for differences between the local and remote systems can lead to mistakes, especially if you work with many sites. It's usually a good thing when the responsibility can be passed to the code,
Copy link to clipboard
Copied
Rob,
Your reply makes no sense. I'd be interested to hear what DeafBoyz has to say about it since the question was directed to him and all...
best,
Shocker ![]()
Copy link to clipboard
Copied
as i tried to explain in my first post, (maybe not all that well but i tried) the path to the file is different on the remote and localhost. Normally a file refrence can be structured to not make this a big deal. But in this particular situation xampp does not recognize the short path or the FULL PATH TO way of doing things. I agree it sucks, but it is what it is. as long as the if else is structured effeciently and securely, it would make a cross platform solution. Plus some poeple only use the clipbucket cms locally, kindof like a picture album, this way they can use it too.
Thanks Rob, thats kindof what I was leaning towards, just wasnt sure if there was a better way of doing it. This topic i found a few places on the clip bucket forum and neither of them had a solid cross platform solution. Just thought id check with the adobe crowd before i posted a solution.![]()
My final code if anyone is curious:
if($_SERVER['DOCUMENT_ROOT'] !== 'C:/xampp/htdocs')
{
//works for remote
require 'adodb/adodb.inc.php';
}else{
//works for localhost
require 'C:\xampp\htdocs\videoz\includes\adodb\adodb.inc.php';
}
Thanks a lot everyone!
Copy link to clipboard
Copied
Shocker,
Besides the situation the OP descibed, which seems to be solved, there are of course other situations where a local environment and a remote environment cannot be the same. For instance, SSL may be required for payment processing on the remote site, but can't work on the testing environment. If you disable the SSL requirement on those scripts for your testing site, you may inadvertently upload the non-secure scripts to the remote site. Having the script check the environment is a good way to deal with situations like this.
So as I said "It's usually a good thing when the responsibility can be passed to the code"
Find more inspiration, events, and resources on the new Adobe Community
Explore Now