Page 1 of 1

Remember the url of an iframe?

Posted: Wed May 16, 2012 7:21 pm
by clifft
I'm new to php and need a little help. I'm looking to create a solution to accomplish the following...

Background

- I have a search engine that is developed in php that i'm taking a wack at modifying.
- Every page on the site contains an iframe. The user can use this iframe to search for and display search result listings.
- I've read about the sins of iframes but I have a strategy that I think is appropriate, however, I'm open to others that better serve an SEO strategy.

Functionality I'm seeking

When the user clicks on a listing displayed in the search results within the iframe, it will load the linked content as the parent page, which also contains an iframe. When the new page loads, I want to maintain the search results in the iframe from the previous page.

My train of thought for a solution

Capture the URL of the iframe before loading a new parent page by saving it as a session, then, call the saved session information as the src attribute for the new iframe being loaded in the parent window.

FYI - The reason I want to capture the iframe's URL is because the search results displayed in the iframe are defined by parameters in the iframe's URL.

2 things I need help with

1. How do you save the current iframe's URL in a session.

I got the following to work in the iframe...

Code: Select all

echo "<input name=page type=hidden value=searchfile.php?" . $_SERVER['QUERY_STRING'] . ">";
but I'm not sure how the start session works, I'm thinking I need to assign an id to the session so it does not interfere with any other session.

Code: Select all

session_start();
$_SERVER['QUERY_STRING'] 
---what comes next?

2. How do I call the session information into the "src" attribute of the iframe of the new page that is loaded. I'm thinking javascript but I'm curious if their is a better solution using php without taxing the server.

Re: Using a session to remember the url of an iframe

Posted: Thu May 17, 2012 3:31 am
by AGISB
Basically you have to add the search query to the iframe url and work with the get values to get the desired output.

This is quite simple when the iframe page is on the same domain or subdomain as the session remains the same. You take your search query and save it to the session after submit and take this Sessionquery to add it to the iframe url.

The code depends how you get the form value of the search to the page that works with them. Is it post or get?

Re: Using a session to remember the url of an iframe

Posted: Thu May 17, 2012 5:53 am
by clifft
Thanks AGISB for the reply.
Yes, the iframe pulls content from the same domain and I'm using GET.

Re: Remember the url of an iframe?

Posted: Thu May 17, 2012 7:49 pm
by clifft
Little response. I'm guessing people cringe at the word iframe. I believe in this instance they may be appropriate for an SEO Strategy, however, I'm open to other suggestions.

Re: Remember the url of an iframe?

Posted: Thu May 17, 2012 8:01 pm
by Benjamin
Just store the search results in a session and redisplay the data on subsequent page requests as required.