Create an Image Trackback for an outside web publisher to link to my site

我的未来我决定 提交于 2019-12-25 07:27:36

问题


We're trying to create a trackback system where an outside web publisher can put some html on a page on their website that links back to a specific product page on our site. Let's call it a 'badge' for purposes of this question.

Once they've inserted the badge, we want to identify this, then grab the < h1 > and first < p > as a teaser to comprise a link from our site back to theirs and write all this stuff to our database. Then, our users can see the title and first bit of their page, then decide if they want to see more.

Here's what we've done (not much I'm afraid):

<a href="http://www.mysite.com/abc.html">
<img alt="abc" src="http://www.mysite.com/logo.gif" style="width:200px;height:100px" />       
</a>

We're planning to build an admin page to do the last part of grabbing the < h1> and < p> and posting it to the live database, etc. and we'll figure this out later.

However, the middle step (identifying that this piece of html has been used) we're at a loss.

Is this something we should be doing through a log file....I have no clue even how to begin thinking about it.

A little direction of where to begin working on this problem would be very helpful.

Thanks in advance!!


回答1:


This is one approach.

You give them HTML which looks something like:

<a href="http://www.mysite.com/abc.html">
    <img alt="abc" src="http://www.mysite.com/logo.php" style="width:200px;height:100px" />       
</a>

Notice that says logo.php, not logo.gif.

logo.php will live on your server. Its purpose is twofold:

  1. Gather information about the page holding the <img> tag
  2. Load and output logo.gif so the users see the image as expected.

If you embed that html on a webpage somewhere, logo.php will have information about where the request for the image originated. Specifically, $_SERVER['HTTP_REFERER'] will give you the complete URL to the page where the img tag resides. It is then up to you to decide how to process and store that information.

I don't know exactly what you want to do, but a very simplified logo.php would look something like this:

<?php
$url = $_SERVER['HTTP_REFERER'];

// do something with $url... 
// it will be something like "http://theirsite.com/wherever/they/pasted/the.html"

// now output the logo image...
header("Content-Type: image/gif");
echo file_get_contents("/path/to/logo.gif");

Keep in mind that every time anyone hits their page with the image tag, logo.php will be run. So don't accidentally create 10000 links back to their site on your site :)



来源:https://stackoverflow.com/questions/14268292/create-an-image-trackback-for-an-outside-web-publisher-to-link-to-my-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!