doujie7497 2013-05-30 02:35
浏览 62

wordpress插件将定义的URL重定向到另一个显示权限错误的url选项页面

i was working on a plugin that can find some special url in wordpress page contents and then if matching URL found then change that url automatically to another url like without giving backlink benfit to that site.

for example : if i have defined a site that start with www.site2.com and i wants to redirect this to another site www.site3.com

now pluging will convert url found www.site.com on page to www.site.com/og.php=www.site2.com now if user clicks this url this will be redirected to www.site3.com

after inslalling and activating plugin found urls are converting but when i clicks them getting error "/og.php" file not found

And when i have tried to open option page to add more url or changing some settings on page it's giving me error "you do not have permission to access this page"

below you can check my codes for both pages

CODE FOR OPTION PAGE:

<?php
/*
Author: Tasleem
Author URI: http://www.alitips.in
Description: Admin options for Automatic Affiliate Links on the fly
*/

$location = get_option('siteurl') . '/wp-admin/st_auto_affiliate_links_options.php'; // Form Action URI


// Set a few defaults to get people started and use as examples
add_option('st_aal_before', 'http://www.hammacher.com
http://www.thinkgeek.com
http://www.blogrush.com');

add_option('st_aal_after', 'http://www.dpbolvw.net/j6117p-85-7NPVWPRURNPORVORWO?url=%ENCODED_TARGET%&cm_ven=CJ&cm_cat=1511450&cm_pla=1781363&cm_ite=Hammacher+Schlemmer&sid=%TARGET%
http://www.anrdoezrs.net/se121lnwtnvACIJCEHEACBEGHEDF?url=%ENCODED_TARGET%&sid=cg-%TARGET%
http://www.blogrush.com/r58661417');;

/*check form submission and update options*/
if ('process' == $_POST['stage'])
{
    update_option('st_aal_before', $_POST['st_aal_before']);
    update_option('st_aal_after', $_POST['st_aal_after']);
}

/* Get options for form fields */
$st_aal_before = get_option('st_aal_before');
$st_aal_after = get_option('st_aal_after');

?>


<div class="wrap"> 
  <h2><?php _e('Automatic Affiliate Links Options', 'st_ts_') ?></h2> 
  <form name="form1" method="post" action="<?php echo $location ?>&amp;updated=true">
    <input type="hidden" name="stage" value="process" />
    <table width="100%" cellspacing="2" cellpadding="5" class="editform">
    <tr>
        <td width="50%" valign="top"><strong>URLs that start with</strong></td>
        <td><strong>Replace with</strong></td>
    </tr>
    <tr>
        <td valign="top"><textarea name="st_aal_before" id="st_aal_before" style="width: 95%;" rows="15" cols="50"><?php echo $st_aal_before; ?></textarea></td>
        <td valign="top"><textarea name="st_aal_after" id="st_aal_after" style="width: 95%;" rows="15" cols="50"><?php echo $st_aal_after; ?></textarea>
        <strong>Tokens:</strong><br>
        <i>%TARGET%</i> - original URL<br>
        <i>%ENCODED_TARGET%</i> - original URL encoded to be html friendly
        </td>
    </tr>
    </table>
        <p class="submit">
      <input type="submit" name="Submit" value="<?php _e('Update Options', 'st_ts_') ?> &raquo;" />
    </p>
      </form>
</div>

code for programming page that will redirect url

<?php
/*
Plugin Name: Automatic Affiliate Links
Plugin URI: http://www.alitips.in
Author: Tasleem
Author URI: http://www.alitips.in
Description: Changes Affiliate URLs to local URL which will then be forwarded by the local script
Date: September 18th, 2007
Version: 1.1
History:
18/09/2007  1.0.0   Initial Version
19/9/2007   1.0.01  Modifed (hacked) to cope with multiple ?s and &s in the initial URL

*/


$OutGoingURL =   "/og.php";

function ConvertURLs($aText)
{
    global $OutGoingURL;

    $st_aal_before = get_option('st_aal_before');
    $searchfor = explode("
", trim($st_aal_before));

    for($i = 0; $i < count($searchfor); $i++)
    {
        $searchfor[$i] = "|href=['\"](" . $searchfor[$i] . ".*)/?['\"]|Ui";
    }

    get_option('siteurl');
    $aText = preg_replace($searchfor, "href='" . get_option('siteurl'). "$OutGoingURL?url=$1" ."'", $aText);    
    return $aText;
}


if(strstr( $_SERVER['REQUEST_URI'], $OutGoingURL))
{
    $st_aal_after = get_option('st_aal_after');
    $replacewith = explode("
", trim($st_aal_after));

    $st_aal_before = get_option('st_aal_before');
    $searchfor = explode("
", trim($st_aal_before));
    for($i = 0; $i < count($searchfor); $i++)
    {
        $searchfor[$i] = "|(" . $searchfor[$i] . ").*|Ui";
    }

    $lURL = $_SERVER['QUERY_STRING'];
    // Bit of a hack, the query string may have multiple ? and & so just knock the url= bit off the querystring
    $lURL = substr($lURL, 4, strlen($lURL));
    $lNewURL = preg_replace($searchfor, $replacewith, $lURL);   
    $lNewURL = str_replace("%TARGET%", $lURL, $lNewURL);;
    $lNewURL = str_replace("%ENCODED_TARGET%", urlencode($lURL), $lNewURL);;

    header("location: $lNewURL"); 
    exit;
}


function st_affiliate_links_options_page()
{
    add_options_page('Automatic Affiliate Links Options', 'Automatic Affiliate Links', 9, 'st_auto_affiliate_links_options.php');
}


if (function_exists('add_action') && function_exists('add_filter')) 
{
    add_action('admin_head', 'st_affiliate_links_options_page');
    add_filter('the_content', 'ConvertURLs', 1);
}
?>
  • 写回答

1条回答 默认 最新

  • dtqqq24248 2013-08-14 18:16
    关注

    You still have a lonnnnnng way young grasshopper. Your first issue to be solved, is you 'insufficient privileges issue'. Secondly you will want to use the wordpress link for your form action which is : <?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>

    Then, you may want to look into session handling for other various issues that you are bound to run into. See here: http://devondev.com/2012/02/03/using-the-php-session-in-wordpress/

    I would share more links, but I know that Google will lead you to the right place. I know this to be true, as I was in the same situation 1 week ago.

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏