Better way of swapping between localhost and server?

This is a discussion on Better way of swapping between localhost and server? within the PHP Language forums, part of the PHP Programming Forums category; Hi, I am currently developing on a windows XP machine and upload my code via subversion to a linux server. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-12-2006
elyob
 
Posts: n/a
Default Better way of swapping between localhost and server?

Hi,
I am currently developing on a windows XP machine and upload my code via
subversion to a linux server. All was great, until I just tried to test out
using Zend Studio.

if ($_SERVER['REMOTE_ADDR']=="127.0.0.1") {
$base_path="../path/";
}
else {
$base_path="/home/account/public_html/path/";
}

Zend studio didn't like 'REMOTE_ADDR' - Undefined index: REMOTE_ADDR,
which then meant it couldn't include any files and fell over.

I am also having problems using cookies and sessions ..

if ($_SERVER['REMOTE_ADDR']=="127.0.0.1") {
session_set_cookie_params(7200);
} else {
session_set_cookie_params(7200, '/', '.example.com');
}

This works fine on server, but not locally.

Any suggestions on whether I am doing the right method?

Thanks



Reply With Quote
  #2 (permalink)  
Old 09-12-2006
Peter Fox
 
Posts: n/a
Default Re: Better way of swapping between localhost and server?

Following on from elyob's message. . .
>Hi,
>I am currently developing on a windows XP machine and upload my code via
>subversion to a linux server. All was great, until I just tried to test out
>using Zend Studio.
>
>if ($_SERVER['REMOTE_ADDR']=="127.0.0.1") {
> $base_path="../path/";
>}
>else {
> $base_path="/home/account/public_html/path/";
>}

Base your switch on where the host is (ie what you're _really_ trying to
switch on) not on who's calling.

eg (but many alternatives) $_ENV['COMPUTERNAME']
or
$_SERVER['SERVER_NAME']

Server name will be localhost when running locally.



--
PETER FOX Not the same since the e-commerce business came to a .
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Reply With Quote
  #3 (permalink)  
Old 09-12-2006
elyob
 
Posts: n/a
Default Re: Better way of swapping between localhost and server?


"Peter Fox" <peterfox@eminent.demon.co.uk.not.this.bit.no.html > wrote in
message news:GCpotVA1vtBFFwX1@eminent.demon.co.uk...
> Following on from elyob's message. . .
>>Hi,
>>I am currently developing on a windows XP machine and upload my code via
>>subversion to a linux server. All was great, until I just tried to test
>>out
>>using Zend Studio.
>>
>>if ($_SERVER['REMOTE_ADDR']=="127.0.0.1") {
>> $base_path="../path/";
>>}
>>else {
>> $base_path="/home/account/public_html/path/";
>>}

> Base your switch on where the host is (ie what you're _really_ trying to
> switch on) not on who's calling.
>
> eg (but many alternatives) $_ENV['COMPUTERNAME']
> or
> $_SERVER['SERVER_NAME']
>
> Server name will be localhost when running locally.


Yup, that's a better way. However it still doesn't work in Zend Studio ....

Same error .. "Notice: D:\htdocs\\foo.php line 12 - Undefined index:
SERVER_NAME"



Reply With Quote
  #4 (permalink)  
Old 09-12-2006
Dikkie Dik
 
Posts: n/a
Default Re: Better way of swapping between localhost and server?

I don't like global variables much, but I make an exception for
settings. Just create a settings.php file that contains all
server-dependent settings as assignments to global variables and include
that file from the pages that needs them. You can put the settings file
outside the webroot, so it will be hard to get for a normal web user.

Best regards

elyob wrote:
> Hi,
> I am currently developing on a windows XP machine and upload my code via
> subversion to a linux server. All was great, until I just tried to test out
> using Zend Studio.
>
> if ($_SERVER['REMOTE_ADDR']=="127.0.0.1") {
> $base_path="../path/";
> }
> else {
> $base_path="/home/account/public_html/path/";
> }
>
> Zend studio didn't like 'REMOTE_ADDR' - Undefined index: REMOTE_ADDR,
> which then meant it couldn't include any files and fell over.
>
> I am also having problems using cookies and sessions ..
>
> if ($_SERVER['REMOTE_ADDR']=="127.0.0.1") {
> session_set_cookie_params(7200);
> } else {
> session_set_cookie_params(7200, '/', '.example.com');
> }
>
> This works fine on server, but not locally.
>
> Any suggestions on whether I am doing the right method?
>
> Thanks
>
>
>

Reply With Quote
  #5 (permalink)  
Old 09-12-2006
Chuck Anderson
 
Posts: n/a
Default Re: Better way of swapping between localhost and server?

elyob wrote:
> "Peter Fox" <peterfox@eminent.demon.co.uk.not.this.bit.no.html > wrote in
> message news:GCpotVA1vtBFFwX1@eminent.demon.co.uk...
>
>> Following on from elyob's message. . .
>>
>>> Hi,
>>> I am currently developing on a windows XP machine and upload my code via
>>> subversion to a linux server. All was great, until I just tried to test
>>> out
>>> using Zend Studio.
>>>
>>> if ($_SERVER['REMOTE_ADDR']=="127.0.0.1") {
>>> $base_path="../path/";
>>> }
>>> else {
>>> $base_path="/home/account/public_html/path/";
>>> }
>>>

>> Base your switch on where the host is (ie what you're _really_ trying to
>> switch on) not on who's calling.
>>
>> eg (but many alternatives) $_ENV['COMPUTERNAME']
>> or
>> $_SERVER['SERVER_NAME']
>>
>> Server name will be localhost when running locally.
>>

>
> Yup, that's a better way. However it still doesn't work in Zend Studio ....
>
> Same error .. "Notice: D:\htdocs\\foo.php line 12 - Undefined index:
> SERVER_NAME"
>
>
>
>

How about $_SERVER['HTTP_HOST'] ?

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Everyone's journey should be different,
so that we all are enriched
in new and endless ways
*****************************
Reply With Quote
  #6 (permalink)  
Old 09-12-2006
Jerry Stuckle
 
Posts: n/a
Default Re: Better way of swapping between localhost and server?

elyob wrote:
> "Peter Fox" <peterfox@eminent.demon.co.uk.not.this.bit.no.html > wrote in
> message news:GCpotVA1vtBFFwX1@eminent.demon.co.uk...
>
>>Following on from elyob's message. . .
>>
>>>Hi,
>>>I am currently developing on a windows XP machine and upload my code via
>>>subversion to a linux server. All was great, until I just tried to test
>>>out
>>>using Zend Studio.
>>>
>>>if ($_SERVER['REMOTE_ADDR']=="127.0.0.1") {
>>>$base_path="../path/";
>>>}
>>>else {
>>>$base_path="/home/account/public_html/path/";
>>>}

>>
>>Base your switch on where the host is (ie what you're _really_ trying to
>>switch on) not on who's calling.
>>
>>eg (but many alternatives) $_ENV['COMPUTERNAME']
>>or
>>$_SERVER['SERVER_NAME']
>>
>>Server name will be localhost when running locally.

>
>
> Yup, that's a better way. However it still doesn't work in Zend Studio ....
>
> Same error .. "Notice: D:\htdocs\\foo.php line 12 - Undefined index:
> SERVER_NAME"
>
>
>


Are you trying to run this directly under Zend Studio instead of from a
web server? If so, your $_SERVER variables won't be set.

You could get by with

if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] ==
'whatever')

But you'll probably run into other problems, also (i.e. $_POST variables
not set, etc.).





--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #7 (permalink)  
Old 09-12-2006
Petr Vileta
 
Posts: n/a
Default Re: Better way of swapping between localhost and server?

elyob wrote:
> Hi,
> I am currently developing on a windows XP machine and upload my code
> via subversion to a linux server. All was great, until I just tried
> to test out using Zend Studio.
>
> if ($_SERVER['REMOTE_ADDR']=="127.0.0.1") {
> $base_path="../path/";
> }
> else {
> $base_path="/home/account/public_html/path/";
> }
>

And what say PHP constant PHP_OS ?

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:59 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0