Get iframe Data?

Hi Guys,

I’m loading an iframe up which will display text saying like “data submitted”. How do i get what comes up in the frame into a variable. For example.

$iframe = iframedata

Any help would be great.

Thanks

PS: Just donated £10 GBP to Cancer Research UK as a thank you for the continued support SitePoint users are giving me. Your help has not gone unnoticed.

I think this needs to be moved to the Javascript forum actually.

To the the contents of an <iframe> all you need is the page URL and a cool PHP function called file_get_contents(). See the below example for a reference on how to accomplish this…

<?php

$contents = file_get_contents('http://www.google.com');
echo $contents; // Output the page contents

Thanks for this, so will the page actually load as the URL i will be using will be submitting data through its URL, for example:

domain.com/submit.php?name=scott&email=scot@gmail.com

and so on. So will the page actually load and submit the data or just get the source code?

Thanks

Ad, What are you trying to do generally?

We submit data to one of our partners through an iframe, when we submit the data through their URL (e.g domain.com/submit.php?name=scott&email=scot@gmail.com) it will say text like “Data Added To Database”. What we need to do is grab that text and place it in a PHP Variable so we can add it do the database under the data we just submitted.

e.g:

iframe loads www.domain.com/submit.php?name=scott&email=scot@gmail.com

"Data Added To Database" is outputted on domain.com/submit.php?name=scott&email=scot@gmail.com

$iframecontent = "Data Added To Database"

Do you understand what im trying to do?

Thank you.

so you run site a, but not site b. Site b holds a form that people enter data in, and site a wants the data from site b?

correct.

You would need to have somebody on site b code their page to e-mail you, add to your database, or however you want the data. An iframe points somewhere else, so you would need to control the page you link to.

This wont be possible, they wouldnt do it i know this already. Is there any type of code which can do what we need? (linux only).

Thanks

Nope. I can rephrase your question so you can see the issue.

I want to code a page so I can capture users login info when they attempt to login to [bank name]

Any URL in general should work in the file_get_contents() function.

SL - he simply cant do what he’s wanting to…

Mmmh… not necessarily?

While sort of in a grey-area type of enviroment, you could generate the form on your own site, capture the data, and pass it on to the other site’s form. (Full disclosure would be morally required, naturally.)

True StarLion. I assuming this was something like signup with our affliliates sort of deal, so making their own isn’t possible.

We actually pass user registration data onto one of our clients which they pay us for, we just need to grab the output text when we pass the details onto them so we can see if the data was added to their database or not. Thats all I’m trying to do :slight_smile:

2 ways to do it;

  1. Duplicate the other site’s HTML for the form, change the form handler to your own site. Catch the data yourself, do whatever you need to with it, and then use cURL to pass it to the client’s form handler. Client gets their data, but the browser stays on your website.

  2. Duplicate the other site’s HTML for the form, leave the form handler as the client’s catcher. Add a javascript AJAX call to the form’s onsubmit to catch the data, and return true to send the browser to the client’s site with the data.

There is no form though, we get the data passed onto us the same way we send it to our client.

e.g domain.com/submit.php?name=scott&gender=male

Doesnt matter iv got a guy doing the code for me, charging me $20 to do it and he said he was going to use cURL to do it. :slight_smile:

Thanks guys.

I assume that on submit that data is added to your database? If so, and they logically coded the form which lives on their site and you link to via iframe, the code should be like.


<?php
  if( /*all data is valid*/ ){
   // add to your database
   // add to theirs
   echo "data submitted";
} else { echo "retry";}

Ew. GET data passing. eww.