homepage Welcome to WebmasterWorld Guest from 54.205.7.136
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

    
redirect external link to specified page on wordpress
I search for plugin redirect external link to another page on my site with
SaleF




msg:4561437
 6:06 pm on Apr 4, 2013 (gmt 0)

hi all
I was search since yesterday for plugin that redirect external link to another page on my site with waiting time leading to external link ..

I'm looking for features similar what we see In download sites Like download.com or filehippo etc (My site is freeware download site too)

this is example external link on one of my post
http ://example.com/device-driver-v12.exe
in post named mysite.com/postname.html
All my posts have "post meta" variable I name it 'Download'
I include download on my theme single.php file .


I Already find plugin called Short URL Plugin (google it) but it only short links manually without waiting time etc ..
link format are similar mysite.com/u/23

I'm not have that expert on PHP to modify the plugin
but after I see the source code figure out it's not that hard to make this work ..

Here is contents of exit link page (u.php)

<?php
if(file_exists('../../../wp-config.php')){ require('../../../wp-config.php'); } else { require('wp-config.php'); }
global $table_prefix, $wpdb;
$get_id = $_SERVER['QUERY_STRING'];
$pieces = explode("|", $get_id);
$get_id = $pieces[0];
$variables = $pieces[1];
$table_name = $table_prefix . "short_url";
if($get_id){
$site_redirect = $wpdb->get_var("SELECT link_url FROM $table_name WHERE link_id='$get_id'");
if($site_redirect){
$wpdb->query("UPDATE $table_name SET link_count = link_count + 1 WHERE link_id='$get_id'");
$site_redirect = str_replace("$2", $variables, $site_redirect);
header("Location: $site_redirect");
exit;
}
echo "<h2>Short URL Not Found</h2>";
echo "<p>Sorry but the URL you entered was not found to redirect anywhere. Please check the link and try again.</p>";
}
As us see the plugin connect to DB grebe shorted link from it table ..
So can I embed this feature to single.php file to change the links automatically and make u.php detect the new link .

 

lorax




msg:4561562
 1:54 am on Apr 5, 2013 (gmt 0)

So just to be sure I understand this. A user clicks on a link for [yoursite.com...]

You want to make the user wait for some period of time before you redirect them to [yoursite.com...]

And the wait time would be what? Seconds?

lucy24




msg:4561565
 2:15 am on Apr 5, 2013 (gmt 0)

../../../wp-config.php

:: running around screaming in horror ::

You will, of course, not use anything remotely resembling this construction in your real code. I count three sets of ../ which is three more than anyone needs.

Normally wait time exists for a reason. For example, "You will be redirected to suchandsuch after five seconds" so the user knows what is happening. (Why the user needs to know this is not perfectly clear to me, since these pages never have a "click to forget the whole thing" option.) At a minimum, you're allowing time for the user to read something. What happens during the wait on your site? Preferably something other than "We're mad that you want to leave our site, so we're going to sulk for five seconds to punish you."

Sorry but the URL you entered was not found to redirect anywhere. Please check the link and try again.

... to which your average user will respond "Huh? I didn't enter anything, I just clicked on a link!"

You want to make the user wait for some period of time before you redirect them to ... yoursite.com/somedir/adifferentfile

Isn't it the other way around? If you click on a link to
someone-else's-site.com/anything

you are first sent to
your-own-site.com/transfer-point

and sit there for some period of time before you're allowed to continue. I was thinking something like the "Leaving Facebook" page-- except there you have to take further action to say "Yes, yes, I really mean it."

SaleF




msg:4561576
 3:21 am on Apr 5, 2013 (gmt 0)

OK you not get it right . this is little confusing ..
lucy24 lorax
the code is not mine its from wordpress plugin her is it link [wordpress.org ]
As I said I know little about PHP and wordpress plugins ..if their is security issue in that script please let me know
and about ../../../wp-config.php path I think the author us it to reach wp-config.php on site root from current plugin path which is
../wp-contens/plugin/short-url-plugin
waiting period will be 5 seconds and I done it now .
the page will continue promotional banner (not aggressive on of course )

This similar to what you see in adf.ly
To hide download link in first post page ..
make it as link from my site like example on my first post

I already done all that ..using Short URL Plugin wordpress Plugin .
And I add meta refresh instead of php redirect . so count down are work .
short link work too..

The only issue is short link add from plugin admin area not added automatically specially their is at less 260 link needed to modify .

I was thinking similar feature could be easy found on wordpress plugnis but look harder then what it look like .

lucy24




msg:4561578
 3:43 am on Apr 5, 2013 (gmt 0)

The only issue is short link add from plugin admin area not added automatically specially their is at less 260 link needed to modify.

Can you say this again in different words please? I understand that you have many many links in this form, so you want something to happen automatically. You don't want to edit 260 posts.

about ../../../wp-config.php path I think the author us it to reach wp-config.php on site root from current plugin path which is
../wp-contens/plugin/short-url-plugin

If you need to use the part of the code that refers to /wp-config.php then give a site-absolute URL like

:: shuffling papers ::

$_SERVER['DOCUMENT_ROOT'] . "/exact-path-here/wp-config.php"

Do you really need "if file exists" and "require" as entirely separate commands? It makes me think of those apache envelopes that say <IfModule...>. Either you've got the wp-config file or you haven't.

SaleF




msg:4561587
 4:16 am on Apr 5, 2013 (gmt 0)

I understand that you have many many links in this form, so you want something to happen automatically. You don't want to edit 260 posts

the post like could changed frequency that mean I need to do it twice first on plugin admin are and the second on post links (some post have more then one link )
As I said This required developing another plugin that scan all posts link and change is to shorted links and store it on specified DB table .
about site-absolute URL looks like the plugin author [profiles.wordpress.org ] I think he done this part badly .
I delete hat like because I put u.php file on site root folder /html .

I ask you and any one else who have expert on wordpress is the code
require('wp-config.php'); safe to use .I search and found no one use it .
g1smd




msg:4561588
 4:19 am on Apr 5, 2013 (gmt 0)

The file_exists and require are pretty standard PHP ways of doing things.

Whilst using ../../../ in a URL is a very bad idea, it's ta common way of doing things for PHP includes. Remember, this directive isn't going to generate a HTTP request, it's an internal filesystem fetch from one file to another within PHP. Since the software is installed in fixed folders, it's no big deal to use relative references to access other files within the filesystem.

lucy24




msg:4561619
 7:28 am on Apr 5, 2013 (gmt 0)

Is the path relative to the php file that's doing the work, independent of where the visible outer file lives? (I have stubbed my toe many times on a fairly analogous situation: background images called from external css files shared by pages in various locations :()

g1smd




msg:4561631
 8:16 am on Apr 5, 2013 (gmt 0)

Yes, it is relative to the PHP file where the directive is used. It has nothing at all to do with URLs or HTTP.

CSS, JS and images are requested using a URL and HTTP. In that case it is important to state the full path in the link, not use the ../ method.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved