Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php link redirect 1

Status
Not open for further replies.

bccamp

Technical User
Jan 20, 2005
69
I have a db full of links in the format:
Code:
<a href="[URL unfurl="true"]http://www.link.com">link</a><img[/URL] src="[URL unfurl="true"]http://img.location.com">[/URL]
I am trying to execute these links from a header redirect by parsing the
Code:
<a href=
but it doesn't work every time. Some of the links have the
Code:
<img src=
listed first so the redirect isn't working every time. My question: is there a way to execute this link from within a php script in its entirety?
 
sorry for not being clear.

My website has icons for other sites with tracking embedded. My db has the links to the websites with the tracking included in the links. I'm trying to make each icon connect to a "redirect page" that accesses the db, grabs the links that are in the form
Code:
<a href="[URL unfurl="true"]http://webpage.com">Page</a><img[/URL] src="[URL unfurl="true"]http://codepage.com">[/URL]
and redirect to that webpage without the user clicking another link. I tried using
Code:
header("location: $dblink")
but it will not execute because of the <a href=" portion. I then tried removing the <a href=" with str_replace and ereg_replace, but again this did not work with some of the links. Do you have any other suggestions on 1) how to execute the db link in its current form without any other user input (preferred), or 2) a way to pull out the
Code:
[URL unfurl="true"]http://webpage.com[/URL]
disregarding everything else? Any help is greatly appreciated.
 
off the top of my head a quick soultion might be this

Code:
$linkarr=explode("\"",$dblink);

$yourlink=$linkarr[1];

there are prob better ways of doing this
 
My first thought would be to change your database schema. Instead of storing the link in its entire HTML form, I recommend storing the URL in one column and enough information in other columns that your code can reproduce the tags.

That way, your intermediate page can easily fetch the correct data from the database.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks, this works better than my code was, but it looks as though many of the links still will not execute. I think some of the embedded tracking codes listed in the
Code:
<img
code is needed by the tracking comany that tracks my links. I'll keep trying. Thanks again.
 
you can reach the img one with
Code:
$linkarr[3];

just in case you didnt know
 
Also thanks to sleipnir214, but my db aready has about 400 entries in this format. Also, I think I would run into the problem I alluded to before of the tracking code listed in the
Code:
<img
be required for SOME of the links, but not all. That's why I think it would be great if I could have a 'magic clicker' that activates the complete link from the db, but if that's not possible, I'll pursue a different approach, less the magic clicker:). Thanks for trying to help me.
 
Thanks Steven, but I tried that as well. The codes supplied to me, unfortunately, are not standardized, so $linkarr[3] is not the same for each link. Example:
Code:
$linkarr[4]=width
in one link. Thanks.
 
use this find the link


Code:
function searchforlink($a){
	foreach($a as $k=>$v){
		if( stristr($v,"http") ) {
		return $v;
		}
	}
}

$linkarr=explode("\"",$dblink);

echo searchforlink($linkarr);
 
Thanks again Steven, the code works great. The problem I'm running into is the
Code:
<img="http://
is getting viewed when it is listed first in the link. I'm working now to remove that whole section
Code:
<img src="[URL unfurl="true"]http://page.com">[/URL]
to only leave behind the portion of the link that has the web URL, not the IMG URL. Your code will be perfect for my use then. thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top