0

どの曲が再生されたかを記録するために、Flash MP3 プレーヤーから PHP スクリプトに変数を渡しています。次に、PHP スクリプトで 1 つの変数を表示し、それを Amazon リンクに含めます。

これは私が持っているものですが、動作させることができないようです。

<?php
$var1  = $_POST['var1']; //get the Artist Name and Title from Flash and store it in a PHP variable
$var2 = $_POST['var2']; //ignored
//This lines combines the two variables into one string. 
//To concatinate vars in PHP use a period or dot ".", much like Flash uses a plus sign "+". 

$add = $var1 . "+" . $var2 . "|";
//opens or creates (if it doesn't already exist) our text file (songsplayed.txt) 
//for writing (not reading) and places the pointer at the end.
$open = fopen('songsplayed.txt', 'a'); 
//writes to our specified file our string
$write = fwrite($open, $add); 

echo $var1;
echo

<a type="amzn" search=\"$var1\" category="music">
<img border="0" src="/buttons/buy-now-button-amazon.png" alt="Buy now @ Amazon"></a>
?>
4

2 に答える 2

0

これを試すことができます。

<?php
// minimal xss protection
$var1 = htmlentities($_POST['var1'], ENT_QUOTES, 'UTF-8');
$var2 = htmlentities($_POST['var2'], ENT_QUOTES, 'UTF-8');
// one-line append
file_put_contents('songsplayed.txt', sprintf("%s+%s\r\n", $var1, $var2));
// proper echo'ing
echo $var1,
     '<a type="amzn" search="'. $var1 .'" category="music">',
     '<img border="0" src="/buttons/buy-now-button-amazon.png" alt="Buy now @ Amazon"></a>';
?>
于 2013-01-30T22:16:31.487 に答える
0

HTMLを引用符で囲まずにページにエコーしようとしているようです。代わりにこれを試してください:

<?php
$var1  = $_POST['var1']; //get the Artist Name and Title from Flash and store it in a PHP variable
$var2 = $_POST['var2']; //ignored
//This lines combines the two variables into one string. 
//To concatinate vars in PHP use a period or dot ".", much like Flash uses a plus sign "+". 

$add = $var1 . "+" . $var2 . "|";
//opens or creates (if it doesn't already exist) our text file (songsplayed.txt) 
//for writing (not reading) and places the pointer at the end.
$open = fopen('songsplayed.txt', 'a'); 
//writes to our specified file our string
$write = fwrite($open, $add); 

echo $var1;
?>
<a type="amzn" search="<?php echo $var1; ?>" category="music">
<img border="0" src="/buttons/buy-now-button-amazon.png" alt="Buy now @ Amazon"></a>
于 2013-01-30T21:09:59.627 に答える