如何获取更改图像的src并存储到php变量?

时间:2014-01-18 08:02:19

标签: javascript php html

该文件名为Step1.php。 html代码只显示下面三个单词的图片,用javascript更改图像src。(图像变化非常好)

我能够使用session成功将src带到下一页。它回显了images/rose.png

问题是当图像改变时(通过onclick功能),

在下一页上它似乎没有回显新的图像src,但仍然是回声images/rose.png

HTML:

<img id="flower" src="images/rose.png" />

<table>
<tr>
<td><div onclick="rose()"> rose </div></td>
<td><div onclick="dove()"> dove </div></td>
<td><div onclick="lily()"> lily </div></td>
</tr>
</table>

JavaScript的:

function O(obj) {
if (typeof obj == 'object') return obj;
else return document.getElementById(obj)
}

function rose(){ flowersrc = 'images/rose.png';}
function dove(){ flowersrc = 'images/dove.png';}
function dove(){ flowersrc = 'images/lily.png';}

O("flower").src = flowersrc;

PHP:

<?php
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
session_start();
$html = file_get_contents('Step1.php');
$dom = new DOMDocument;
$dom->loadHTML($html);
$tag = $dom->getElementById('flower');
$flowersrc = $tag->getAttribute('src');

$_SESSION['flower'] = $flower;
?>

第二个文件的PHP:

 <?php
    header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
    session_start();
    $flower = $_SESSION['flower'];
    echo $flower;
 ?>

0 个答案:

没有答案