ツイッターカードの画像URLをPHPの変数で動的に変更したいのですが、headの最初に書くと変数imageの定義前なので空になってしまいます。しかし、メタタグをソースのようにphpのあとに書くとツイッターカードのエラーになります。どうしたらいいでしょうか?
<!DOCTYPE html> <html lang="ja"> <head> <?php session_start(); include_once 'dbconnect.php'; if(!isset($_SESSION['user'])) { header("Location: index3.php"); } // ユーザーIDからユーザー名を取り出す $query = "SELECT * FROM ???? WHERE user_id=".$_SESSION['user'].""; $result = $mysqli->query($query); $result = $mysqli->query($query); if (!$result) { print('クエリーが失敗しました。' . $mysqli->error); $mysqli->close(); exit(); } // ユーザー情報の取り出し while ($row = $result->fetch_assoc()) { global $username; $username = $row['username']; $user_id = $row['user_id']; $email = $row['email']; global $image; $image = $row['image']; } // データベースの切断 $result->close(); ?> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:site" content="http://????/home.php"> <meta name="twitter:creator" content="@Sarah"> <meta name="twitter:title" content="Parade of Fans for Houston’s Funeral"> <meta name="twitter:description" content="NEWA"> <meta name="twitter:image" content="http://feed.littlestar.jp/???/images/<?php echo $image;?>">
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。