facebook og:image 不从 php 文件中获取与 URL 相呼应的图像
facebook og:image does not fetch image from php file that echoes the URL
facebook OG 从回显中获取图像 URL,这可能吗?
因为我包含了一个 php 文件,它将回显图像 URL 但是当我检查共享调试器时,内容是空的
<meta property="og:image" content="" />
我的元标签 :
<meta property="og:image" content ="<?php include "meta_gambar.php"?>">
和 php 文件:
<?php
$module=$_GET['module'];
$id=$_GET['id'];
if($module=='detailproduk'){
//prepare query
$stmt=mysqli_prepare($con,"SELECT gambar FROM produk WHERE id_produk=?");
if($stmt===false){
die("Prepare error" . htmlspecialchars($mysqli->error));
}
//Bind parameters
$bp=mysqli_stmt_bind_param($stmt,"i",$id);
if($bp===false){
die("Binding error" . htmlspecialchars($stmt->error));
}
//Execute query
$bp=mysqli_stmt_execute($stmt);
if($bp===false){
die("Execute error" . htmlspecialchars($stmt->error));
}
//bind result
$bp=mysqli_stmt_bind_result($stmt,$gambar);
if($bp===false){
die("Result bind error" . htmlspecialchars($stmt->error));
}
//Fetch
$bp=mysqli_stmt_fetch($stmt);
if($bp===false){
die("Fetching error" .htmlspecialchars($stmt->error));
}
$image = "http://images.rajafotocopy.com/foto_produk/$gambar";
}else{
$image = "http://images.rajafotocopy.com/raja.png";
}
echo"$image";
?>
更新
我刚刚尝试将 URL 图像直接放到 og:image content
上,效果很好
但包含一个 php 文件,该文件将回显 URL 仍然会导致空白
听起来当前路径不是包含文件所在的位置。尝试指定包含文件的完整路径,例如:
include $_SERVER['DOCUMENT_ROOT'] . "/path/to/meta_gambar.php";
另一种选择是使用 require
而不是 include
- 如果文件或路径有问题,require
会产生一个错误并给你一些想法错了。
facebook OG 从回显中获取图像 URL,这可能吗?
因为我包含了一个 php 文件,它将回显图像 URL 但是当我检查共享调试器时,内容是空的
<meta property="og:image" content="" />
我的元标签 :
<meta property="og:image" content ="<?php include "meta_gambar.php"?>">
和 php 文件:
<?php
$module=$_GET['module'];
$id=$_GET['id'];
if($module=='detailproduk'){
//prepare query
$stmt=mysqli_prepare($con,"SELECT gambar FROM produk WHERE id_produk=?");
if($stmt===false){
die("Prepare error" . htmlspecialchars($mysqli->error));
}
//Bind parameters
$bp=mysqli_stmt_bind_param($stmt,"i",$id);
if($bp===false){
die("Binding error" . htmlspecialchars($stmt->error));
}
//Execute query
$bp=mysqli_stmt_execute($stmt);
if($bp===false){
die("Execute error" . htmlspecialchars($stmt->error));
}
//bind result
$bp=mysqli_stmt_bind_result($stmt,$gambar);
if($bp===false){
die("Result bind error" . htmlspecialchars($stmt->error));
}
//Fetch
$bp=mysqli_stmt_fetch($stmt);
if($bp===false){
die("Fetching error" .htmlspecialchars($stmt->error));
}
$image = "http://images.rajafotocopy.com/foto_produk/$gambar";
}else{
$image = "http://images.rajafotocopy.com/raja.png";
}
echo"$image";
?>
更新
我刚刚尝试将 URL 图像直接放到 og:image content
上,效果很好
但包含一个 php 文件,该文件将回显 URL 仍然会导致空白
听起来当前路径不是包含文件所在的位置。尝试指定包含文件的完整路径,例如:
include $_SERVER['DOCUMENT_ROOT'] . "/path/to/meta_gambar.php";
另一种选择是使用 require
而不是 include
- 如果文件或路径有问题,require
会产生一个错误并给你一些想法错了。