Jump to content


Photo

Getting parent variable with php from child with iframes


  • Please log in to reply
4 replies to this topic

#1 Noesis

Noesis

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 19 November 2013 - 04:05 PM

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, 19 November 2013 - 04:08 PM.


#2 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,329 posts

Posted 19 November 2013 - 04:17 PM

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)



#3 Noesis

Noesis

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 19 November 2013 - 04:31 PM

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.



#4 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,329 posts

Posted 19 November 2013 - 05:05 PM

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, 19 November 2013 - 05:05 PM.


#5 Noesis

Noesis

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 19 November 2013 - 06:14 PM

ty Ch0cu3r, I'll give it  a try.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com