簡體   English   中英

使用Facebook分享鏈接發送參數

[英]Sending parameters with a Facebook share link

我有一個Facebook共享鏈接,我想向其中添加userid的參數,以便可以在Facebook共享鏈接中添加特定於用戶的內容。

我的鏈接如下

  <a href="http://www.facebook.com/sharer/sharer.php?u=<my site url>?UserId=[User-Id] target="_blank"><img src="assets/img/facebookBtn.jpg" alt=""></a>

我的meta鏈接是

    <meta property="og:site_name" content="Group D World Cup Predictor" />
    <meta property="og:url" content="http://www.example.com/extension/" />
    <meta property="og:type" content="website" />
    <meta property="og:title" content="I predicted [Winning-Team] to win Group D!" />
    <meta property="og:description" content="I predicted [Winning-Team] to win Group D! Give your World Cup prediction for a chance to win a 4 night holiday." />
    <meta property="og:image" content="http://www.example.com/extension/assets/img/sharingImage.jpg" />
    <meta prosperty="fb:admins" content="myadminmu==number" />

通過測試我的php代碼,好像在發送它的那一點上我能夠看到用戶ID。 所以我的第一個問題是這是通過URL發送userId參數的正確方法。

其次,即時通訊使用$ _GET檢索網址UserId,這是檢索userId的正確方法,我是否需要通過其他方法訪問它?

class HomeController extends BaseController {

  public function Index() 
  {
    $userId = $_GET['UserId'];

    $viewModel = new StdClass;

    $viewModel->WinningTeam = strtoupper(with(new FinalizeController)->getWinningTeam($userId)->Name);

    return View::make('home', $viewModel);

  }
}

我知道getWinningTeam可以正常工作,所以它一直指向URL,並且不會將UserId作為參數發送到主頁。 由meta標簽使用,以訪問有關該用戶的相關信息。

我讀過很多文章說它已經貶值了,您可能不發送帶有特定參數的鏈接,但是將其與實現方法進行對比。

任何指針將不勝感激

麥克風

首先,請嘗試避免在URL中使用大寫字母(對於查詢參數也是如此)。

然后,您還應該對URL進行編碼,因為這本身就是查詢參數...這是我用來對URL進行編碼/解碼的在線工具=> http://meyerweb.com/eric/tools/dencoder/

因此,假設您的網址是http://www.example.com/mypage?userid=0123456 ,這是您的鏈接:

<a href="http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.example.com%2Fmypage%3Fuserid%3D0123456" target="_blank"><img src="assets/img/facebookBtn.jpg" alt=""></a>

最后,為了遵循“從不信任用戶輸入”規則,您不能只使用$_GET['userid']接收原始查詢參數並直接使用它……而是應該檢查檢索到的值是否為您期望的類型(例如:如果您的userId應該是整數,則為is_numeric()等)。

實際上,您應該只閱讀w3schools上有關PHP過濾器的這篇文章 ,因為我不是一個好的老師。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM