p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Working Offline to test PHP scripts, How to!


Message #1 by "Tan Le" <tanle@a...> on Mon, 16 Jul 2001 01:56:02
Hi all:

 

I really like the Beginning Book PHP4.  I have succeeded in setting up the 

server with IIS and PHP4.  I am on page 113 of the book.  The server runs 

fine when it's hooked to the Internet.  It's a laptop so I take it to the 

bookstore and read and try the examples but it does not work offline.  How 

do I configure it so that I can work offline and be able to process PHP 

scripts successfully?  Please advise!

 

Sincerely,

 

Tan Le

PHP beginner.
Message #2 by Paul <pagin@k...> on Mon, 16 Jul 2001 15:21:10 -0400
I bet this has smething to do with name resolution. If you were to try

http://localhost or http://IPaddress, it would work until you try to enter a

directory name like http://IPaddress/PHPCode. At that point it tries to use the

"real" name of the server, http://domainname/PHPCode. That requires a name

resolution by a DNS server, which is online. To get around this, make an entry

in you C:\WINDOWS\HOSTS file that says "IPaddress youHostname". Just to be sure,

also enter the same into your C:\WINDOWS\LMHOSTS file. And make sure the files

do NOT have an extension such as ".sam" or anything at all.



> bookstore and read and try the examples but it does not work offline.  How

> do I configure it so that I can work offline and be able to process PHP

> scripts successfully?  Please advise!



Message #3 by "Tan Le" <tanle@a...> on Mon, 16 Jul 2001 16:43:08 -0500
Thanks for your insight.  I am still not sure.  I am using win 2000 and

IIS.  The server is http://hummingbird. I store all html and php files

under C:\Inetpub\wwwroot.  Since it is a client computer with IP

192.168.0.12 (something like that), it keeps looking for that when it's

offline.  In IIS, the IP address is (All Unassigned) and Home Directory

is c:\inetpub\wwwroot.  I don't see C:\WINDOWS\HOSTS or

C:\WINDOWS\LMHOSTS that you mentioned.  Can you shed more light?



TL



-----Original Message-----

From: root@t... [mailto:root@t...] On Behalf

Of Paul

Sent: Monday, July 16, 2001 2:21 PM

To: beginning php

Subject: [beginning_php] Re: Working Offline to test PHP scripts, How

to!





I bet this has smething to do with name resolution. If you were to try

http://localhost or http://IPaddress, it would work until you try to

enter a directory name like http://IPaddress/PHPCode. At that point it

tries to use the "real" name of the server, http://domainname/PHPCode.

That requires a name resolution by a DNS server, which is online. To get

around this, make an entry in you C:\WINDOWS\HOSTS file that says

"IPaddress youHostname". Just to be sure, also enter the same into your

C:\WINDOWS\LMHOSTS file. And make sure the files do NOT have an

extension such as ".sam" or anything at all.



> bookstore and read and try the examples but it does not work offline.



> How do I configure it so that I can work offline and be able to 

> process PHP scripts successfully?  Please advise!



Message #4 by Jesse Goerz <jgoerz@l...> on Mon, 16 Jul 2001 20:13:38 -0500
The host file is what was used back in the beginning days of the internet.  

It had all the address-name pairs in one file.  Everyone who had a computer 

connected to the internet used to have to download that file once a week or 

so and install it on their machine so they could "see" all the other 

machines.  Nowadays, there are too many computers connected for this to be 

feasible, so they came up with DNS.



What computers do now (at least on most Unix-type machines) is look first at 

the local hosts file, and if they can't find the address to a machine there 

they look it up in DNS.  



So you need to create a hosts file in the directories which Paul mentioned 

earlier.  You can use notepad or wordpad to do this.  It should look 

something like this:



192.168.0.12	name_of_computer short_name_of_computer



Mine looks like this:

127.0.0.1	localhost

192.168.1.1	fileserver.goerz.net fileserver



This is on a linux machine but the format should be the same for you.



The short name isn't really needed but instead of typing the full name you 

can just type the short one in your browser.



After creating the file in notepad make sure you save the file *without* 

extensions.  The file should be called:



hosts



That's it.  No period or .txt or anything.  After you create it just copy it 

into the directories Paul mentioned and see if that works.



HTH,

Jesse



On Monday 16 July 2001 16:43, Tan Le wrote:

> Thanks for your insight.  I am still not sure.  I am using win 2000 and

> IIS.  The server is http://hummingbird. I store all html and php files

> under C:\Inetpub\wwwroot.  Since it is a client computer with IP

> 192.168.0.12 (something like that), it keeps looking for that when it's

> offline.  In IIS, the IP address is (All Unassigned) and Home Directory

> is c:\inetpub\wwwroot.  I don't see C:\WINDOWS\HOSTS or

> C:\WINDOWS\LMHOSTS that you mentioned.  Can you shed more light?

>

> TL

>

> -----Original Message-----

> From: root@t... [mailto:root@t...] On Behalf

> Of Paul

> Sent: Monday, July 16, 2001 2:21 PM

> To: beginning php

> Subject: [beginning_php] Re: Working Offline to test PHP scripts, How

> to!

>

>

> I bet this has smething to do with name resolution. If you were to try

> http://localhost or http://IPaddress, it would work until you try to

> enter a directory name like http://IPaddress/PHPCode. At that point it

> tries to use the "real" name of the server, http://domainname/PHPCode.

> That requires a name resolution by a DNS server, which is online. To get

> around this, make an entry in you C:\WINDOWS\HOSTS file that says

> "IPaddress youHostname". Just to be sure, also enter the same into your

> C:\WINDOWS\LMHOSTS file. And make sure the files do NOT have an

> extension such as ".sam" or anything at all.

>

> > bookstore and read and try the examples but it does not work offline.

> >

> > How do I configure it so that I can work offline and be able to

> > process PHP scripts successfully?  Please advise!



Message #5 by Paul <pagin@k...> on Tue, 17 Jul 2001 05:19:03 -0400
> So you need to create a hosts file in the directories which Paul mentioned

> earlier.  You can use notepad or wordpad to do this.  It should look

> something like this:



Small correction. I said the files are in "c:\windows", which is correct for

Win9x systems. In Win2k they should be in "c:\winnt\system32\drivers\etc".



Message #6 by "Tan Le" <tanle@a...> on Tue, 17 Jul 2001 12:07:19 -0500
Hello, thanks for your quick response!  There is already a 'hosts' file

under the path you mentioned.  Below is what it shows.  My other Win2000

computer has the same.  However, IIS auto-detects the IP address under

'Default Website' properties.  For example: when it's online, the IP is

192.168.0.44 (it changes when I relog) and gateway is 192.168.0.1 (this

is my server computer that shares the Internet with my laptop).  But

when I disconnect the LAN, my laptop has no IP address...(under

C:>ipconfig).  I tried adding (and saved like it is w/o .sam) the

virtual IP address and hummingbird, my computer name, such as:

192.168.0.44 hummingbird but that should not work because I am offline

which releases the virtual IP address and default to 'none'.  But when

offline, IIS sees 127.0.01 as described in the hosts file.  But no luck

when I typed http://127.0.0.1/index.html.  What I am looking for is that

OFFLINE "IP address"?  It does not make sense that I have to log on the

Internet in order to execute the PHP.  I am afraid that after finding a

fix to work offline, the PHP needs to be configured to work offline.  I

still need help if I did anything wrong.



Sincerely,

TL



# Copyright (c) 1993-1999 Microsoft Corp.

#

# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.

#

# This file contains the mappings of IP addresses to host names. Each

# entry should be kept on an individual line. The IP address should

# be placed in the first column followed by the corresponding host name.

# The IP address and the host name should be separated by at least one

# space.

#

# Additionally, comments (such as these) may be inserted on individual

# lines or following the machine name denoted by a '#' symbol.

#

# For example:

#

#      102.54.94.97     rhino.acme.com          # source server

#       38.25.63.10     x.acme.com              # x client host



127.0.0.1       localhost





-----Original Message-----

From: root@l... [mailto:root@l...] On

Behalf Of Paul

Sent: Tuesday, July 17, 2001 4:19 AM

To: beginning php

Subject: [beginning_php] Re: Working Offline to test PHP scripts, How

to!





> So you need to create a hosts file in the directories which Paul 

> mentioned earlier.  You can use notepad or wordpad to do this.  It 

> should look something like this:



Small correction. I said the files are in "c:\windows", which is correct

for Win9x systems. In Win2k they should be in

"c:\winnt\system32\drivers\etc".



Message #7 by Paul <pagin@k...> on Tue, 17 Jul 2001 13:38:40 -0400
Here's the solution, I'm pretty sure now. Give your laptop a static IP. Any Web

server should have one. Just write down the information from "ipconfig /all" and

type it into your network settings window.



This is important. How many computers connect to the ICS computer?



A note about the hosts and lmhosts files: The hosts file is used to resolve Unix

or domain names like "www.dpagin.net" while the lmhosts files tries to resolve

Micro$oft computer names like "ABOO".





Tan Le wrote:



> Hello, thanks for your quick response!  There is already a 'hosts' file

> under the path you mentioned.  Below is what it shows.  My other Win2000

> computer has the same.  However, IIS auto-detects the IP address under

> 'Default Website' properties.  For example: when it's online, the IP is

> 192.168.0.44 (it changes when I relog) and gateway is 192.168.0.1 (this

> is my server computer that shares the Internet with my laptop).  But

> when I disconnect the LAN, my laptop has no IP address...(under

> C:>ipconfig).  I tried adding (and saved like it is w/o .sam) the

> virtual IP address and hummingbird, my computer name, such as:

> 192.168.0.44 hummingbird but that should not work because I am offline

> which releases the virtual IP address and default to 'none'.  But when

> offline, IIS sees 127.0.01 as described in the hosts file.  But no luck

> when I typed http://127.0.0.1/index.html.  What I am looking for is that

> OFFLINE "IP address"?  It does not make sense that I have to log on the

> Internet in order to execute the PHP.  I am afraid that after finding a

> fix to work offline, the PHP needs to be configured to work offline.  I

> still need help if I did anything wrong.



Message #8 by "Tan Le" <tanle@a...> on Tue, 17 Jul 2001 20:15:19 -0500
when online the computer gets three addresses: http://hummingbird,

http://192.168.0.20, or http://127.0.0.1.  when offline only the latter

is active.  there is a file 'hosts' under system32\drivers\etc that

names 127.0.0.1 localhost but when I changed that to 1.1.1.1 (for easy

typing), it does not affect in IIS.  strange!



Anyhow, it works offline very well.  Thanks so much gentlemen!  You guys

make me think really hard especially I never used PHP, IIS, Win2000,

MySQL before.  I am a newbie.



-----Original Message-----

From: Paul [mailto:pagin@k...] 

Sent: Tuesday, July 17, 2001 12:39 PM

To: beginning php

Subject: [beginning_php] Re: Working Offline to test PHP scripts, How

to!





Here's the solution, I'm pretty sure now. Give your laptop a static IP.

Any Web server should have one. Just write down the information from

"ipconfig /all" and type it into your network settings window.



This is important. How many computers connect to the ICS computer?



A note about the hosts and lmhosts files: The hosts file is used to

resolve Unix or domain names like "www.dpagin.net" while the lmhosts

files tries to resolve Micro$oft computer names like "ABOO".





Tan Le wrote:



> Hello, thanks for your quick response!  There is already a 'hosts' 

> file under the path you mentioned.  Below is what it shows.  My other 

> Win2000 computer has the same.  However, IIS auto-detects the IP 

> address under 'Default Website' properties.  For example: when it's 

> online, the IP is 192.168.0.44 (it changes when I relog) and gateway 

> is 192.168.0.1 (this is my server computer that shares the Internet 

> with my laptop).  But when I disconnect the LAN, my laptop has no IP 

> address...(under C:>ipconfig).  I tried adding (and saved like it is 

> w/o .sam) the virtual IP address and hummingbird, my computer name, 

> such as: 192.168.0.44 hummingbird but that should not work because I 

> am offline which releases the virtual IP address and default to 

> 'none'.  But when offline, IIS sees 127.0.01 as described in the hosts



> file.  But no luck when I typed http://127.0.0.1/index.html.  What I 

> am looking for is that OFFLINE "IP address"?  It does not make sense 

> that I have to log on the Internet in order to execute the PHP.  I am 

> afraid that after finding a fix to work offline, the PHP needs to be 

> configured to work offline.  I still need help if I did anything 

> wrong.



Message #9 by Paul <pagin@k...> on Wed, 18 Jul 2001 00:48:33 -0400
Never change the 127.0.0.1 localhost entry. That is known as the loopback

address. Basically, it fools you computer into thinking it is using a network

interface when it is communicating with itself.



What was the actual solution?





Tan Le wrote:



> when online the computer gets three addresses: http://hummingbird,

> http://192.168.0.20, or http://127.0.0.1.  when offline only the latter

> is active.  there is a file 'hosts' under system32\drivers\etc that

> names 127.0.0.1 localhost but when I changed that to 1.1.1.1 (for easy

> typing), it does not affect in IIS.  strange!

>

> Anyhow, it works offline very well.  Thanks so much gentlemen!  You guys

> make me think really hard especially I never used PHP, IIS, Win2000,

> MySQL before.  I am a newbie.



Message #10 by "Tan Le" <tanle@a...> on Tue, 17 Jul 2001 21:13:46 -0500
I found out that localhost must use that 127.0.0.1.  So I cannot change

that to 1.1.1.1.  Disregard the last email per hosts file.



TL



-----Original Message-----

From: Tan Le [mailto:tanle@a...] 

Sent: Tuesday, July 17, 2001 8:15 PM

To: beginning php

Subject: [beginning_php] Re: Working Offline to test PHP scripts, How

to!





when online the computer gets three addresses: http://hummingbird,

http://192.168.0.20, or http://127.0.0.1.  when offline only the latter

is active.  there is a file 'hosts' under system32\drivers\etc that

names 127.0.0.1 localhost but when I changed that to 1.1.1.1 (for easy

typing), it does not affect in IIS.  strange!



Anyhow, it works offline very well.  Thanks so much gentlemen!  You guys

make me think really hard especially I never used PHP, IIS, Win2000,

MySQL before.  I am a newbie.



-----Original Message-----

From: Paul [mailto:pagin@k...] 

Sent: Tuesday, July 17, 2001 12:39 PM

To: beginning php

Subject: [beginning_php] Re: Working Offline to test PHP scripts, How

to!





Here's the solution, I'm pretty sure now. Give your laptop a static IP.

Any Web server should have one. Just write down the information from

"ipconfig /all" and type it into your network settings window.



This is important. How many computers connect to the ICS computer?



A note about the hosts and lmhosts files: The hosts file is used to

resolve Unix or domain names like "www.dpagin.net" while the lmhosts

files tries to resolve Micro$oft computer names like "ABOO".





Tan Le wrote:



> Hello, thanks for your quick response!  There is already a 'hosts'

> file under the path you mentioned.  Below is what it shows.  My other 

> Win2000 computer has the same.  However, IIS auto-detects the IP 

> address under 'Default Website' properties.  For example: when it's 

> online, the IP is 192.168.0.44 (it changes when I relog) and gateway 

> is 192.168.0.1 (this is my server computer that shares the Internet 

> with my laptop).  But when I disconnect the LAN, my laptop has no IP 

> address...(under C:>ipconfig).  I tried adding (and saved like it is 

> w/o .sam) the virtual IP address and hummingbird, my computer name, 

> such as: 192.168.0.44 hummingbird but that should not work because I 

> am offline which releases the virtual IP address and default to 

> 'none'.  But when offline, IIS sees 127.0.01 as described in the hosts



> file.  But no luck when I typed http://127.0.0.1/index.html.  What I

> am looking for is that OFFLINE "IP address"?  It does not make sense 

> that I have to log on the Internet in order to execute the PHP.  I am 

> afraid that after finding a fix to work offline, the PHP needs to be 

> configured to work offline.  I still need help if I did anything 

> wrong.








$subst('Email.Unsub')



Message #11 by chris_camplejohn@e... on Thu, 19 Jul 2001 02:14:23
Hi,



I have watched this thread with much amusement for the last few days.



It appears to me, that you are trying to sync the php files from the 

server to your laptop which is all well and good. However, it sounds like 

you have no web server running on your laptop! So when you come offline, 

you have nothing to process the PHP pages! Install IIS on you laptop! and 

copy the files from your server onto your root web directory on the laptop.



If you have got IIS installed on your laptop, then make sure you have the 

files in your root dir, C:\Inetpub\wwwroot by default.



In answer to all the IP address nonsense, http://localhost and 

http://127.0.0.1 are the same thing and use the MS Loopback Adaptor to 

point to the local machine, instead of a network interface. You can also 

use your machine name i.e http://mymachine so if you want to run the php 

file index.php and it is located in C:\Inetpub\wwwroot, then type 

http://localhost/index.php This also works in sub directories, contrary to 

someones comment.



One last thing.. about when you go online.. As you say, you are given an 

IP address by your ISP, this can be used also, but only when online, as 

the address is released as soon as you come offline. Giving your machine a 

static address is of no advantage, as this just means that you will have a 

fourth address to use! How many does one need?!..lol



Anyways.. hope this helps..

Cheers

Chris



> Hi all:

>  

> I really like the Beginning Book PHP4.  I have succeeded in setting up 

the 

> server with IIS and PHP4.  I am on page 113 of the book.  The server 

runs 

> fine when it's hooked to the Internet.  It's a laptop so I take it to 

the 

> bookstore and read and try the examples but it does not work offline.  

How 

> do I configure it so that I can work offline and be able to process PHP 

> scripts successfully?  Please advise!

>  

> Sincerely,

>  

> Tan Le

> PHP beginner.
Message #12 by root <paul@d...> on Thu, 19 Jul 2001 18:15:50 -0400
> I have watched this thread with much amusement for the last few days.



You have watched, but it seems like you didn't catch all of it. You seem to 

understand the use of IIS, but is your experience is limited to Micro$oft 

systems, which try to isolate the user from underlying network issues? In any 

case, without actually sitting down to work on the problem directly, neither 

of us can be sure of the actual problems.





> In answer to all the IP address nonsense, http://localhost and

> http://127.0.0.1 are the same thing and use the MS Loopback Adaptor to

> point to the local machine, instead of a network interface. You can also

> use your machine name i.e http://mymachine so if you want to run the php

> file index.php and it is located in C:\Inetpub\wwwroot, then type

> http://localhost/index.php This also works in sub directories, contrary to

> someones comment.



True, 127.0.0.1 and localhost refer to the same loopback interface. This was 

never a question. Since localhost and 127.0.0.1 are resolved locally by the 

hosts file, it should always work.





> One last thing.. about when you go online.. As you say, you are given an

> IP address by your ISP, this can be used also, but only when online, as

> the address is released as soon as you come offline. Giving your machine a

> static address is of no advantage, as this just means that you will have a

> fourth address to use! How many does one need?!..lol



The PC running Internet Connection Sharing (ICS) assigned DHCP IPs to any PC 

networked to it. The ISP's IP is only assigned to the ICS PC, not the rest of 

the private network. Using a static IP allows the laptop to always have the 

same settings and to work offline without as much trouble.



Message #13 by Jesse Goerz <jgoerz@l...> on Mon, 23 Jul 2001 12:39:50 -0500
On Monday 23 July 2001 10:14, Tan Le wrote:

> Thanks very much Jessie for your excellent comment.  I'd greatly

> appreciate your detailed regards.  It's hard to find people like you who

> tells explicit explanation to every problem.  I did a search and found

> no sight of the file common_db.inc.  The book didn't have a CD.  The

> back of the book does not have a CD sleeve so I don't think it was sold

> with a CD.  Where can I find that file and attach it to

> c:\inetpub\wwwroot?  The server p2p.wrox.com was down last night so I

> couldn't find it.  Please instruct me a site that I can download.

>

> Sincerely,

>

> Tan Le

>



Sorry Tan, I can't help you here.  Here's what I'd look for though:



1.  Check the index of the book and see if they reference the file or the 

particular function which is causing you problems.  Even if it is a "custom" 

fucntion they may have shown you how to write it in an earlier passage.  

2.  I don't have the book so this is just a guess.  If you can't find the 

function or include file anywhere you could just create your own.  Again, I 

don't have the book but maybe it tells you how to write the function and put 

it in an include file.



HTH,

Jesse



Message #14 by root <paul@d...> on Mon, 23 Jul 2001 13:47:15 -0400

http://www.wrox.com/Books/Book_Details.asp?section=11_4&isbn=1861003730&subject=&subject_id



Go to the link above and click "Download Code". Then, at the link above, 

click on "Book Errata" for corrections to the code and the book.

Message #15 by "Tan Le" <tanle@a...> on Mon, 23 Jul 2001 13:27:57 -0500
Thanks, I was practicing chapter 11.  The link below has the codes for

all chapters.  The common_db.inc is in chapter 12 and 13.  No wonder I

can't find it yet.  Thank you whoever sent this link.



Sincerely,



Tan Le



-----Original Message-----

From: root [mailto:paul@d...] 

Sent: Monday, July 23, 2001 12:47 PM

To: beginning php

Subject: [beginning_php] Re: Working Offline to test PHP scripts, How

to!







http://www.wrox.com/Books/Book_Details.asp?section=11_4&isbn=1861003730&

subject=&subject_id



Go to the link above and click "Download Code". Then, at the link above,



click on "Book Errata" for corrections to the code and the book.


  Return to Index