Jump to content

Load Page with Filler Update


iwato
 Share

Recommended Posts

THE TASK:  

  1. Receive an HTTP query from an external source.
  2. Use the information from the query to obtain information from a data base
  3. Insert the information from the database into a filler page.
  4. Load the filler into the host page in such away that both appear simultaneously.

DILEMMA:

I can perform all of these tasks individually, but I am at a loss as to how to move from Step 3 to Step 4.

DISCUSSION:  I am accustomed to loading a filler into a page that is already opened.  And, I am accustomed to loading a page with information queried from a database.  Although I am pretty sure that I can call a page and load it with a filler whose content is determined by the HTTP query (Steps 1 and 4).  What I have not done and feel awkward about is filling the filler page with information from the database query before displaying both the page and the filler together.

QUESTION:  Any suggestions?

Roddy

Link to comment
Share on other sites

I'm not really clear what you're asking.  If you're handling the request with PHP, then you can get the input data, do whatever you need with the database, load a template or something and populate it, and then I guess load another template for the rest of the page and insert the other template before sending the response to the browser.  Are you already using some kind of template engine?

Link to comment
Share on other sites

Thank you for responding.  I have decided to play with my idea a little before coming back. For, in this way, I will be able to ask a better question dealing specifically with code. In so doing, I may even be able to answer my own question.  

Link to comment
Share on other sites

JSG: 

Quote

If you're handling the request with PHP, then you can get the input data, do whatever you need with the database, load a template or something and populate it.

I have created a form page (sender.php) with a single input field.  The value of this input field is sent via a $_GET superglobal to another page (receiver.php) that:  one, retrieves all of the records from a data base; two, compares the value received from the form page (sender.php) with the values of a field of all of the retrieved records, and three, displays the receiver.php page with the value of another field of the same matched record.  Everything up to this point has now been accomplished.

JSG: 

Quote

... and then I guess load another template for the rest of the page and insert the other template before sending the response to the browser.

Indeed, this is the part that I have yet to overcome.

The displayed result (see above) is the information that should serve as a filler for another page that hosts all such form queries.

QUESTION:  How do I get the information from this filler (receiver.php) to appear in the host page with the host page when the result of the form query is sent to the filler template?

Roddy

Link to comment
Share on other sites

So as to be simpler.

QUESTION ONE:  Is it possible to call a page into which the calling page is itself loaded?

QUESTION TWO: If this is possible, there is likely more than one technique available to achieve the task.  What are they?

Edited by iwato
Link to comment
Share on other sites

Is it possible to call a page into which the calling page is itself loaded?

I'm just not sure what you mean by that.  "Call a page", do you mean get the HTML contents of a page and do something with it?  Are you saying you want to send an ajax request or something, get the response, and add it to the current page?  That's possible.

Link to comment
Share on other sites

Let me try one more time.

Usually, information from an external source is loaded into an HTML page that is already opened.

In my case, the HTML page in which the information is to appear is not yet opened.  What is more, the unopened page in which the processed information is to appear is used for several other purposes and cannot be easily produced from the processing PHP page that produces the information that is to appear in the HTML page.

Roddy

Edited by iwato
Link to comment
Share on other sites

Usually, information from an external source is loaded into an HTML page that is already opened.

What are you, specifically, referring to here.  Are you talking about using Javascript to load content via ajax?  Are you talking about PHP getting data from a database, or sending a request to a remote server or something, and then using that data when it builds the response for the browser?  I'm not sure why it's significant that the source is external, I assume by external you mean a remote server separate from the web server handling the request.

In my case, the HTML page in which the information is to appear is not yet opened.

If you're saying the page isn't loaded by the browser yet, then nothing can happen until the browser sends a request for the page and gets a response from the server.

What is more, the unopened page in which the processed information is to appear is used for several other purposes

What other purposes?  What's the main purpose of this page?  

and cannot be simply produced from the processing PHP page that produces the information that is to appear in the HTML page.

Why not?

I think we're beyond the discussion of abstract concepts and it's time to get specific.

Link to comment
Share on other sites

OK.  We appear to have touched base here:

If you're saying the page isn't loaded by the browser yet, then nothing can happen until the browser sends a request for the page and gets a response from the server.

So, I have to

1) Get the PHP page to send a request to the user's browser to open the host HTML page.

2) Force a request from the newly opened HTML page to the PHP page.

3) Receive the response and display it in the HTML page.

This looks like AJAX.  Something that I have never used before, but appears entirely within my reach as I have some knowledge of both Javascript and JSON.

This appears to be something that I can do except for the fact that I do not know who the user is.  Once again,

The TASK

The user clicks on a link on a third party website.

An HTTP request is sent from the third party website to a PHP document hosted on my own webpage that uses the requested information to query a database and make a determination.

But, how does the PHP document know where to send the HTTP request necessary to open the host HTML page in the user's browser?

Roddy

 

Link to comment
Share on other sites

1) Get the PHP page to send a request to the user's browser to open the host HTML page.

No, browsers send requests to the server, and the server sends a response back to the browser.  The browser initiates the connection, not the server.  The server just handles connections that get sent to it.

You use ajax when you have a page that is already open and loaded, and you want to change some content on the page from the server without refreshing the entire page.  You can see it on the forum when you submit a new post and it just adds it to the thread but doesn't refresh the entire page, it sends an ajax request to the server with the post content, the server responds with some sort of response that the Javascript is looking for (maybe HTML markup, maybe a JSON object, etc), and then the ajax callback function updates the page based on the server response.

The user clicks on a link on a third party website.

If it's on a separate domain that's going to be an issue, browsers block ajax requests to domains other than the originating domain for security reasons.  The way to bypass that is to send the ajax request to a local PHP page, which will act as a proxy to send the request to the remote server, get the response, and send it back to the originating page.  It's important to note in that case that the request to the remote server comes from the PHP server, not the user's browser.

I'm still not clear on exactly what you're trying to do.  It sounds like you just want a user to click a link on some other website, to your server.  Like, a regular link like any other link on the internet, that goes to your server, and the user's browser loads the URL on your servers and sees whatever you want them to see.  Just like any other link on any other website.  Is it any different than that?

Link to comment
Share on other sites

Quote

I'm still not clear on exactly what you're trying to do.  It sounds like you just want a user to click a link on some other website, to your server.

The user will click on the third-party website only if he wants.  That is his choice.  i only care about what happens after he clicks.

Quote

Like, a regular link like any other link on the internet, that goes to your server, and the user's browser loads the URL on your servers and sees whatever you want them to see.

Yes and no.

Yes, when the user clicks on the third party website, he is taken to my website, but his action does not open an HTML page, rather an invisible PHP page.  What I need to know is how get this latter page with the .php extention to open an .html page in the user's browser after it has processed the information sent to it from the third-party website.

In addition, I would like that the information processed on the PHP page be transferred to the newly opened HTML page.

Is it clear now?

Roddy 

Link to comment
Share on other sites

I have just discovered that I can use the PHP header( ) function with an URL as the value of the function's location parameter to open the HTML page from the PHP age.

header("Location: $url");

Ostensibly, i could append a query string to the end of the URL and then process this string on the HTML when the page opens.  Would this not require, however, that I change the extension of the HTML page from .html to .php?  Likely not a big deal as the HTML page is still in a stage of development.

Roddy

Link to comment
Share on other sites

It will be my first time to use a session, but I could see the time coming long before I started the current task.  So, now is just as good as time as any, and it looks like using a session will provide me with all of the communication that I need between the PHP and HTML pages.

Once again, Dsonesuk, you have struck home.

Many thanks!

Roddy

Link to comment
Share on other sites

Understood.  But, pages with .php extensions can display HTML.  One of my pages displays no HTML, the other does.  This is what I meant.

Thank you.

Roddy

Link to comment
Share on other sites

It sounds like the regular use case for PHP.  You can have PHP send to the browser any content you want, PHP can output any text content like HTML, CSS, Javascript, etc, you can have it output an image, a PDF document, whatever you want.  So it sounds to me like you're describing the general use case where PHP gets some sort of post or get data as input and produces HTML as output.  You can have your HTML right in the PHP code so that it just prints whatever you tell it to, or you can have it load partial HTML templates in other files, fill in whatever data you want, and assemble the various parts into the final markup.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...