Jump to content

Getting parent variable with php from child with iframes


Recommended Posts

Have a situation where I need to retrieve a parent variable but am unable to modify the parent source code. I also want to apply any solution in a cross domain situation but using PHP coding techniques.

<div class='userbox'>
<div class='avatar'><div class='element_avatar simple medium '><a href="http://thetemplars.enjin.com/profile/2819806" data-minitooltip="Noesis"><img src="http://assets-cloud.enjin.com/users/2819806/avatar/medium.1362825808.png"></a></div></div>
<div class='username'><a href='/profile/2819806' class='element_username'>Noesis</a></div>
<a class='logout' href='/logout'>Logout</a>
</div>

The above shows the relevant section of the output source code in javascript and at the moment and I'm unawares to the actual variable names applied in the process as it is the intellectual property rights are owned by someone else. I'm in contact with their support team however in the hope they can help support retrieval of this information to help support their modular use of bolt-on php applications and pages with their forum use.

 

I'm using PHP as my coding platform and believe there could be useful techniques to extract data from the above that doesn't require the preferred method of a listener or simply isn't possible in the case of a java process from the child when cross domains are in use.

 

Ideally the textual part associated with the class "element_username" or the "data-minitooltip" value could be used as per the username displayed on the parent frame.

 

Could anyone advise of useful techniques how I could extract this information with only being able to apply coding changes in the child php code?

Edited by Noesis

The only way you're going to get access to the variables set by the script is by including the raw PHP source code. If the PHP script is on a completely different site to yours then you are out of luck.

 

Can you define what you mean by PHP variable? Are you wanting to get the username (Noesis) from the source code? (That you can do with PHP)

The only way you're going to get access to the variables set by the script is by including the raw PHP source code. If the PHP script is on a completely different site to yours then you are out of luck.

 

Can you define what you mean by PHP variable? Are you wanting to get the username (Noesis) from the source code? (That you can do with PHP)

 

Yes I simply want to extract that piece of text from the parent source, but from within a child iframe php page.

You can use simplexml xpath for this

$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;

$html_source = file_get_contents('http://sitename,com/filename.php'); // url to webpage

$doc->loadHTML($html_source);
$xml = simplexml_import_dom($doc);

$data = $xml->xpath("//a[@class='element_username']"); // finds <a href="..." class="element_username"></a> tags

printf('<pre>%s</pre>', print_r($data, true)); // see what was found

// echo username
$username = (array) $data[0];
echo 'Username: ' . $username[0];
Edited by Ch0cu3r
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.