How to include optonial info when running on local server?

How to include optonial info when running on local server?

am 31.08.2007 23:45:54 von Chris Heilman

I'm a newbie with php, but experienced with other languages. I'm
maintaining a small site written in php. To ease debugging and updates
I've used an onscreen reference to indicate identity of included files
etc.

I don't really want this reference to be visible to anyone but myself.
So I searched the manual and found some promising predefined variables
that I used in this code snippet:

if ($_SERVER['REMOTE_ADDR'] = "127.0.0.1") {
echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
}
?>

This worked spllendidly when I tested running our site locally using
the XAMPP-bundle. But when I copied the code out to the real server it
seems that all clients are found at 127.0.0.1!

I'm sure there are lots of better ways both to fix my code, and
especially totally different ways to do what I'm trying to achive, any
suggestions very welcome!

--
Christian Aastorp

Re: How to include optonial info when running on local server?

am 01.09.2007 00:07:36 von gosha bine

Christian Aastorp wrote:
> I'm a newbie with php, but experienced with other languages. I'm
> maintaining a small site written in php. To ease debugging and updates
> I've used an onscreen reference to indicate identity of included files
> etc.
>
> I don't really want this reference to be visible to anyone but myself.
> So I searched the manual and found some promising predefined variables
> that I used in this code snippet:
>
> > if ($_SERVER['REMOTE_ADDR'] = "127.0.0.1") {
> echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
> }
> ?>
>
> This worked spllendidly when I tested running our site locally using
> the XAMPP-bundle. But when I copied the code out to the real server it
> seems that all clients are found at 127.0.0.1!
>
> I'm sure there are lots of better ways both to fix my code, and
> especially totally different ways to do what I'm trying to achive, any
> suggestions very welcome!
>

127.0.0.1 is "localhost", i.e. it is the machine the script is running
on, not the user machine. You have to put your real "internet" IP there
(and, of course, you want "==" not "=").

If you don't have a permanent IP, you need other means to
authentication, for example HTTP auth:

if(@$_SERVER['PHP_AUTH_USER'] != 'me' || @$_SERVER['PHP_AUTH_PW'] !=
'secret') {
header('WWW-Authenticate: Basic');
header('HTTP/1.0 401 Unauthorized');
die();
}


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

Re: How to include optonial info when running on local server?

am 01.09.2007 01:13:19 von Stacey

On Aug 31, 5:45 pm, Christian Aastorp <> wrote:
> I'm a newbie with php, but experienced with other languages. I'm
> maintaining a small site written in php. To ease debugging and updates
> I've used an onscreen reference to indicate identity of included files
> etc.
>
> I don't really want this reference to be visible to anyone but myself.
> So I searched the manual and found some promising predefined variables
> that I used in this code snippet:
>
> > if ($_SERVER['REMOTE_ADDR'] = "127.0.0.1") {
> echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
> }
> ?>
>
> This worked spllendidly when I tested running our site locally using
> the XAMPP-bundle. But when I copied the code out to the real server it
> seems that all clients are found at 127.0.0.1!
>
> I'm sure there are lots of better ways both to fix my code, and
> especially totally different ways to do what I'm trying to achive, any
> suggestions very welcome!
>
> --
> Christian Aastorp

Don't know if this is what you're referring to, but you might want to
consider including some sort of a config file...ie. config.inc.php.

In this file, you can set a $DEBUG variable to 0 or 1 and then
reference that to determine whether or not to show your messages. You
just need to change the $DEBUG to false when you move it out of your
development environment. I use this same thing for setting mysql
servers, logins & passwords as well.

Re: How to include optonial info when running on local server?

am 01.09.2007 05:20:53 von luiheidsgoeroe

On Fri, 31 Aug 2007 23:45:54 +0200, Christian Aastorp wrote:

>
> I'm a newbie with php, but experienced with other languages. I'm
> maintaining a small site written in php. To ease debugging and updates=

> I've used an onscreen reference to indicate identity of included files=

> etc.
>
> I don't really want this reference to be visible to anyone but myself.=

> So I searched the manual and found some promising predefined variables=

> that I used in this code snippet:
>
> > if ($_SERVER['REMOTE_ADDR'] =3D "127.0.0.1") {
> echo $level1, '_', $level2, '_', $imageNO, ' ', $display;=

> }
> ?>
>
> This worked spllendidly when I tested running our site locally using
> the XAMPP-bundle. But when I copied the code out to the real server it=

> seems that all clients are found at 127.0.0.1!

Hmmmz, normally this can happen if you mistakingly include files by HTTP=
=

rather then by the normal filesystem.

> I'm sure there are lots of better ways both to fix my code, and
> especially totally different ways to do what I'm trying to achive, any=

> suggestions very welcome!

If debugging is needed, I'd normally try logging it to a file, regardele=
ss =

of who views the page (requests vary, and allthough I try I sadly cannot=
=

envision every single combination of requestvariables). If you want on t=
he =

fly debugging, maybe set and use a custom cookie just for you:

if (isset($_COOKIE['mydebugname']) && =

$_COOKIE['mydebugname']=='mydebugsecret') {
echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
}
?>

Set the cookie somewhere manually or on a protected page.
-- =

Rik Wasmus

My new ISP's newsserver sucks. Anyone recommend a good one? Paying for =

quality is certainly an option.

Re: How to include optonial info when running on local server?

am 01.09.2007 05:29:19 von Jerry Stuckle

Rik Wasmus wrote:
> On Fri, 31 Aug 2007 23:45:54 +0200, Christian Aastorp wrote:
>
>>
>> I'm a newbie with php, but experienced with other languages. I'm
>> maintaining a small site written in php. To ease debugging and updates
>> I've used an onscreen reference to indicate identity of included files
>> etc.
>>
>> I don't really want this reference to be visible to anyone but myself.
>> So I searched the manual and found some promising predefined variables
>> that I used in this code snippet:
>>
>> >> if ($_SERVER['REMOTE_ADDR'] = "127.0.0.1") {
>> echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
>> }
>> ?>
>>
>> This worked spllendidly when I tested running our site locally using
>> the XAMPP-bundle. But when I copied the code out to the real server it
>> seems that all clients are found at 127.0.0.1!
>
> Hmmmz, normally this can happen if you mistakingly include files by HTTP
> rather then by the normal filesystem.
>

Alternatively, is there a possibility there's a proxy involved here? I
saw that happen one time - all the log entries showed 127.0.0.1 as the
client address... Customer didn't even realize he could get client ip
numbers (for whatever good they do).

>> I'm sure there are lots of better ways both to fix my code, and
>> especially totally different ways to do what I'm trying to achive, any
>> suggestions very welcome!
>
> If debugging is needed, I'd normally try logging it to a file,
> regardeless of who views the page (requests vary, and allthough I try I
> sadly cannot envision every single combination of requestvariables). If
> you want on the fly debugging, maybe set and use a custom cookie just
> for you:
>
> > if (isset($_COOKIE['mydebugname']) &&
> $_COOKIE['mydebugname']=='mydebugsecret') {
> echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
> }
> ?>
>
> Set the cookie somewhere manually or on a protected page.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: How to include optonial info when running on local server?

am 01.09.2007 09:29:22 von Michael Fesser

..oO(Christian Aastorp <>)

> > if ($_SERVER['REMOTE_ADDR'] = "127.0.0.1") {
^
>
>This worked spllendidly when I tested running our site locally using
>the XAMPP-bundle. But when I copied the code out to the real server it
>seems that all clients are found at 127.0.0.1!

= != ==

Micha

Re: How to include optonial info when running on local server?

am 01.09.2007 13:40:11 von Paul Lautman

Christian Aastorp wrote:
> I'm a newbie with php, but experienced with other languages. I'm
> maintaining a small site written in php. To ease debugging and updates
> I've used an onscreen reference to indicate identity of included files
> etc.
>
> I don't really want this reference to be visible to anyone but myself.
> So I searched the manual and found some promising predefined variables
> that I used in this code snippet:
>
> > if ($_SERVER['REMOTE_ADDR'] = "127.0.0.1") {
> echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
> }
>>
>
> This worked spllendidly when I tested running our site locally using
> the XAMPP-bundle. But when I copied the code out to the real server it
> seems that all clients are found at 127.0.0.1!
>
> I'm sure there are lots of better ways both to fix my code, and
> especially totally different ways to do what I'm trying to achive, any
> suggestions very welcome!

As Michael pointed out, what you are actuall y doing here is assiging the
value "127.0.0.1" to the associative array element $_SERVER['REMOTE_ADDR'].

You should write:
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
}
>
Note the == instead of = and also note the use of single instead of double
quotes around the string, which stops PHP from parsing the string to
discover if any substitution needs to take place.

Re: How to include optonial info when running on local server?

am 01.09.2007 16:49:36 von Aaron Saray

On Sep 1, 6:40 am, "Paul Lautman" wrote:
> Christian Aastorp wrote:
> > I'm a newbie with php, but experienced with other languages. I'm
> > maintaining a small site written in php. To ease debugging and updates
> > I've used an onscreen reference to indicate identity of included files
> > etc.
>
> > I don't really want this reference to be visible to anyone but myself.
> > So I searched the manual and found some promising predefined variables
> > that I used in this code snippet:
>
> > > > if ($_SERVER['REMOTE_ADDR'] = "127.0.0.1") {
> > echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
> > }
>
> > This worked spllendidly when I tested running our site locally using
> > the XAMPP-bundle. But when I copied the code out to the real server it
> > seems that all clients are found at 127.0.0.1!
>
> > I'm sure there are lots of better ways both to fix my code, and
> > especially totally different ways to do what I'm trying to achive, any
> > suggestions very welcome!
>
> As Michael pointed out, what you are actuall y doing here is assiging the
> value "127.0.0.1" to the associative array element $_SERVER['REMOTE_ADDR'].
>
> You should write:
> > if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
> echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
> }
>
> Note the == instead of = and also note the use of single instead of double
> quotes around the string, which stops PHP from parsing the string to
> discover if any substitution needs to take place.

I usually run an if against $_SERVER['SERVER_NAME'] ... so on
localhost the servername is either 'localhost' or like
'mydeveloment.local' - where as the public one will be yoursite.com

Re: How to include optonial info when running on local server?

am 02.09.2007 00:29:53 von colin.mckinnon

On 1 Sep, 08:29, Michael Fesser wrote:
> .oO(Christian Aastorp <>)
>
> > > > if ($_SERVER['REMOTE_ADDR'] = "127.0.0.1") {
>
> ^
>
>
>
> >This worked spllendidly when I tested running our site locally using
> >the XAMPP-bundle. But when I copied the code out to the real server it
> >seems that all clients are found at 127.0.0.1!
>
> = != ==
>
> Micha


Strikes me that this is the easy problem to fix.

There are several things which could cause to this to be true - the
most obvious one to spring to mind is that there is a reverse proxy
sitting in front of the webserver with no transparency on the
conection.

C.

Re: How to include optonial info when running on local server?

am 03.09.2007 22:20:40 von Chris Heilman

On Fri, 31 Aug 2007 23:45:54 +0200, Christian Aastorp <> wrote:

Thanks a lot, all of you! Several usefull corrections and suggestions.
I've recoded my functionality using a cookie that I set using a code
snippet in a different browser-window.

It works well locally, but I haven't tested it remotely.

Thanks again!

--
Christian Aastorp

Re: How to include optonial info when running on local server?

am 03.09.2007 22:23:17 von Jerry Stuckle

Christian Aastorp wrote:
> On Fri, 31 Aug 2007 23:45:54 +0200, Christian Aastorp <> wrote:
>
> Thanks a lot, all of you! Several usefull corrections and suggestions.
> I've recoded my functionality using a cookie that I set using a code
> snippet in a different browser-window.
>
> It works well locally, but I haven't tested it remotely.
>
> Thanks again!
>

Of course, you do realize cookies are stored on the client machine, and
the user can read them? And a savvy user can change them?

Of course, if that's not important, there's no problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: How to include optonial info when running on local server?

am 04.09.2007 09:48:38 von Chris Heilman

On Mon, 03 Sep 2007 16:23:17 -0400, Jerry Stuckle
wrote:


>
>Of course, you do realize cookies are stored on the client machine, and
>the user can read them? And a savvy user can change them?
>
>Of course, if that's not important, there's no problem.

Yes i do realize that, still, thank you for the warning!
The only thing anyone will achieve by setting this cookie is some
filenames visible in the browser-window. These files are located on
the web-server and accessible by other means. Also they are cleared
for publication.

There is a little layer of "security by obscurity" as I'm the only one
with knowledge of the cookies name and function. Our main site will
never set this cookie for any client. Still I'm aware that it's simple
to inspect the php-code to find me out, but its without risk, at least
at the moment.

Thanks again!
--
Christian Aastorp