2010-12-30 29 views
0

です。最後に追加された?url=[xyz][xyz]は短いURLです)の短いURLにアクセスできるようにリンク短縮システム(Yourls)が設定されています。私はそれがあるページのパーマリンクを短くする別のページ(私のMediaWiki wiki上)へのリンクを追加したいと思います。現在のページのURLをリンクに追加する方法で、テンプレートにボタンを追加する必要があります。 MediaWikiはPHPプラットフォームなので、その方が望ましいです(ただし、JavaScriptも問題ありません)。これどうやってするの?現在のURLは

(これは混乱している場合、私は謝罪)

UPDATE:私はとても残念PHP、と恐ろしいです。 私はちょうど

<?php echo'<a href="http://sumov.co.cc/?url=".$_SERVER["REQUEST_URI"]; class="buttonlink ui-state-default ui-corner-all"><span class="ui-icon ui-icon-newwin"></span>Support &rarr;</a>'; ?> 

を入れて、ちょうど(sumov.co.ccは私の短いリンクです)http://sumov.co.cc/?url=に行ったこと。

+0

php経由でアドレスバーにURLを取得しますか? –

+0

はい。それはまさに私が欲しいものです。 – Christopher

答えて

0

無限大です:

$url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

安全に転送するためには、urlencode($url)urldecode($url)をラップアンドラップすることをおすすめします。

0
"http://www.yoursitesdomainname.com".$_SERVER['REQUEST_URI']; 

previouseは現在のページのURLになります。

+0

アップデートをご覧ください。ありがとう – Christopher

0

Babikerが言ったように、URIを返します。私は、URLをフィルタリングまたはexscapingをお勧めします。 WordPressにはesc_urlという関数があります。 WordPressのコアWP-含ま/ formatting.phpラインから

2235年から2281年

/** 
    * Checks and cleans a URL. 
    * 
    * A number of characters are removed from the URL. If the URL is for displaying 
    * (the default behaviour) amperstands are also replaced. The 'clean_url' filter 
    * is applied to the returned cleaned URL. 
    * 
    * @since 2.8.0 
    * @uses wp_kses_bad_protocol() To only permit protocols in the URL set 
    *  via $protocols or the common ones set in the function. 
    * 
    * @param string $url The URL to be cleaned. 
    * @param array $protocols Optional. An array of acceptable protocols. 
    *  Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' if not set. 
    * @param string $_context Private. Use esc_url_raw() for database usage. 
    * @return string The cleaned $url after the 'clean_url' filter is applied. 
    */ 
    function esc_url($url, $protocols = null, $_context = 'display') { 
     $original_url = $url; 

    if ('' == $url) 
     return $url; 
     $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url); 
     $strip = array('%0d', '%0a', '%0D', '%0A'); 
     $url = _deep_replace($strip, $url); 
     $url = str_replace(';//', '://', $url); 
     /* If the URL doesn't appear to contain a scheme, we 
     * presume it needs http:// appended (unless a relative 
     * link starting with/or a php file). 
     */ 
     if (strpos($url, ':') === false && 
     substr($url, 0, 1) != '/' && substr($url, 0, 1) != '#' && !preg_match('/^[a-z0-9-]+?\.php/i', $url)) 
     $url = 'http://' . $url; 

     // Replace ampersands and single quotes only when displaying. 
     if ('display' == $_context) { 
      $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url); 
      $url = str_replace("'", '&#039;', $url); 
     } 

     if (!is_array($protocols)) 
      $protocols = array ('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn'); 
     if (wp_kses_bad_protocol($url, $protocols) != $url) 
     return ''; 

    return apply_filters('clean_url', $url, $original_url, $_context); 
} 

その後、あなたは私があなただったら、私が行ったように私は自分自身のURLを短縮するだろう<?php esc_url(http://www.example.com".$_SERVER['REQUEST_URI'];) ?>

0

を実行します(HTTP ://tecn.me)私は多くのことを学んだし、可能性は、URLを取得するには

関連する問題