Remember the url of an iframe?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clifft
Forum Newbie
Posts: 3
Joined: Wed May 16, 2012 7:12 pm

Remember the url of an iframe?

Post 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.
Last edited by clifft on Thu May 17, 2012 7:45 pm, edited 1 time in total.
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

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

Post 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?
clifft
Forum Newbie
Posts: 3
Joined: Wed May 16, 2012 7:12 pm

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

Post by clifft »

Thanks AGISB for the reply.
Yes, the iframe pulls content from the same domain and I'm using GET.
clifft
Forum Newbie
Posts: 3
Joined: Wed May 16, 2012 7:12 pm

Re: Remember the url of an iframe?

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Remember the url of an iframe?

Post by Benjamin »

Just store the search results in a session and redisplay the data on subsequent page requests as required.
Post Reply