Jump to content

PHP/DOM Hacking anyone?


Recommended Posts

Just wondering if anyone is interested in an article about using PHP/DOM to hook/skin (other) sites on the server level, say if they don't have an rss feed but you want to save the content, change stylesheets, add some script etc?

It's pretty easy so I was thinking about doing an article for Analog.5 if anyone is interested (and my writing isn't too shit).

Link to comment
Share on other sites

Do you mean page scraping? XSLT? Or something with firefox and the user stylesheets? I wouldn't qualify any of those as "Hacking" or "hooking". XSLT would be, by far, the easiest way to do this, as that is what it was designed to do. It probably beats the hell out of a custom written php script that parses the html and what ever. So, to finish up, I have no f-ing clue what you were intending to say, but sure I'll be interested. :D Which will leave me filled with suspense, thrill, and hell I might even learn something.

Link to comment
Share on other sites

It will be about using the DOM server side (not necessarily php but I like it) to do stuff like:

$oDoc = new DomDocument();

if (!@$oDoc->loadHTMLFile($sURL = $_REQUEST['URL']))

die("Failed to load '$sURL'");

$oQuery = new DomXPath($oDoc);

if ($aNodes = $oQuery->query('//div')) {

foreach ($aNodes as $oNode) {

$oNode->setAttribute('style', 'border: 1px solid #FF0000');

$oNode->setAttribute('onclick', "alert('clicked'); return 0;");



echo $oDoc->saveHTML();

Which simply highlights all the 'div' elements on a page in red and adds a javascript onclick handler (no event trapping!) etc if you put it on a php 5+ server and provide URL=<something> in the query string.

Doesn't use XLST, (too site specific) but uses XPath, and can be extended to inject code/content, reposition stuff on screen if you don't like the page layout etc

Link to comment
Share on other sites

Thats cool, It would make for interesting article.

XSLT, along with XPath and XSL-FO, is a subset of XSL. XSLT is a scripting language that takes an XML Document and transforms it in to another Document, not necessarily XML. This case you're going from HTML to HTML. It doesn't have to be site specific, its the programmers choice.

Link to comment
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...