p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Calling PHP scripts without changing documents.


Message #1 by john@e... on Fri, 11 Jan 2002 19:47:42
As a hypertext pre-processor is it possible to interface with scripts 

written in PHP without loading a new document in the browser.



For example:

1. Downloading files from the internet. Is it possible to interface with a 

script written in PHP to download a file (i.e. zip,mp3 etc) like they do 

at PHP.net when you request to download the php.zip. I know this is not 

requesting the same document because if you hover over the link and look 

at your status bar you can tell that it is requesting a new document (plus 

a query of some kind of course).



2.Perhaps I would like to relay an email that interfaces a script written 

on another document.



3. What if I would like to dynamically load a file using the include() 

function into a layer. I would like to interface with a script that loads 

a file after going through some sort of switch() control statement.



In each case I would like that the document not change as a result of 

calling another script. I have seen this done at i.e. php.net, mysql.com. 



Currently I only know of using the $PHP_SELF variable to call the same 

document at which the neccessary script processes on the server and loads 

again.



Is what I am asking at all possible and if so is there some sort of 

technique of function to use?



Thanks
Message #2 by "John" <dotsyntax@r...> on Wed, 16 Jan 2002 14:44:08
I guess that no one understood what I was saying, either because I was not 

being clear or it sounded like I didn't know what I was talking about.



I don't know how else to put it though. All I know is that it is something 

that has been on my mind for a while though. Because PHP is a Hypertext 

Pre-Processor I only thought that requested PHP scripts replaced the 

document in browser memory unless using the $PHP_SELF global variable. 

Then I saw it done otherwise at the download sections of the websites I 

cited in my previous message and I just wanted to know how it was done.
Message #3 by "Nikolai Devereaux" <yomama@u...> on Wed, 16 Jan 2002 12:28:31 -0800

Hey John,



I just went back and reread your old email.



1:  I don't know for sure how they'd do it, but here's my guess:



---- do_download.php ----

<?php

   Header("Location: $file_path/$download_file");

?>

-------------------------





2:  I don't understand what you mean by relay an email that interfaces with

another script...  sorry!



3:  I *think* i can understand what you're saying, but I'm not really clear.





If you want only ONE page to ever be called by your users, it's possible to

have that page simply perform the job of parsing the get and post vars, and

include() the required php files to process those variables.  You can even

put your other PHP files beneath your htdocs directory so that the only file

publically available on your server is your index.php.



Several wiki sites work in a similar fashion -- where you always request the

index page of the wiki dir, and the page that gets displayed is generated by

a switch or if/else chain based on what you send as a query to the server

(be it a get or post).  The body of each case or if block is a simple

include() statment which does the real page processing.



nik





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

> From: John [mailto:dotsyntax@r...]

> Sent: Wednesday, January 16, 2002 2:44 PM

> To: beginning php

> Subject: [beginning_php] Re: Calling PHP scripts without changing

> documents.

>

>

> I guess that no one understood what I was saying, either because

> I was not

> being clear or it sounded like I didn't know what I was talking about.

>

> I don't know how else to put it though. All I know is that it is

> something

> that has been on my mind for a while though. Because PHP is a Hypertext

> Pre-Processor I only thought that requested PHP scripts replaced the

> document in browser memory unless using the $PHP_SELF global variable.

> Then I saw it done otherwise at the download sections of the websites I

> cited in my previous message and I just wanted to know how it was done.

> ---







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

> From: john@e... [mailto:john@e...]

> Sent: Friday, January 11, 2002 7:48 PM

> To: beginning php

> Subject: [beginning_php] Calling PHP scripts without changing documents.

>

>

> As a hypertext pre-processor is it possible to interface with scripts

> written in PHP without loading a new document in the browser.

>

> For example:

> 1. Downloading files from the internet. Is it possible to

> interface with a

> script written in PHP to download a file (i.e. zip,mp3 etc) like they do

> at PHP.net when you request to download the php.zip. I know this is not

> requesting the same document because if you hover over the link and look

> at your status bar you can tell that it is requesting a new

> document (plus

> a query of some kind of course).

>

> 2.Perhaps I would like to relay an email that interfaces a script written

> on another document.

>

> 3. What if I would like to dynamically load a file using the include()

> function into a layer. I would like to interface with a script that loads

> a file after going through some sort of switch() control statement.

>

> In each case I would like that the document not change as a result of

> calling another script. I have seen this done at i.e. php.net, mysql.com.

>

> Currently I only know of using the $PHP_SELF variable to call the same

> document at which the neccessary script processes on the server and loads

> again.

>

> Is what I am asking at all possible and if so is there some sort of

> technique of function to use?

>

> Thanks



Message #4 by "John" <dotsyntax@r...> on Thu, 17 Jan 2002 15:28:20
Nik thanks for the response. You don't know how glad that I am that you 

finally started to get what it was I was trying to say, because I was 

stuck for another way of explaining it. But let me try one more, sort of, 

different approach (just to humor you *smile*).



If you go to http://www.php.net/downloads.php:

-Take for example any of the links, but I will use the first link, the zip 

file, under the heading "Windows Binaries".



-If I click this link it will make this request:                        

http://www.php.net/do_download.php?download_file=php-4.1.1-Win32.zip



-It won't load the document into the client



-It seems to interface with the script there and do the appropriate routine



Notice that all the request are made to the document "do_download.php" and 

I can only assume that "download_file" is an action keyword. Now when you 

click this, the same document isn't being requested(i.e. $PHP_SELF) but 

another one. It doesn't load this document, in this 

case "do_downloads.php", into the client. Rather in this case it knows to 

present the user with a download dialog box.



This could of course be a unique case in which this is the way PHP handles 

download requests. But if it is not do you see the potential that I am 

trying to get at. One could possibly create an entire library of Control 

Statements this way and from all the documents on their website could 

reference this one library and with a keyword execute the apropriate group 

of associative statements without leaving the document they are in.



As for email. I was wondering if this could be done the same way. For 

example, I have an email form in my document 

(http://www.myurl.com/emailme.html). In much the same way that PHP.net 

does their downloads I would like that once the user hits the submit that 

all the variables for the email message be sent to another document i.e. 

http://www.myurl.com/php_library.php?action=mailme. But I don't know how I 

would stop "php_library.php" from loading into the client and 

replacing "email_me.html" and still have the script process 

in "php_library.php". 



I am going to stop now before I start rambling and repeating myself.

Thanks for the help

  Return to Index