更正包含html的脚本的PRG模式代码

时间:2013-08-02 08:38:03

标签: php html

我已经意识到有很多关于PRG,后请求获取模式的说法,但我找不到任何特定的PHP。假设我有包含表单的HTML文件,我在php脚本的末尾包含了HTML,如下所示:

<?php   include '../html/gozd.html';   ?>

现在我想修改我的php脚本,以便用户在刷新浏览器窗口时无法重新发布数据,并且他不能回到不同类型的表单输出等之间。基本上Web浏览器不应该记住任何除了表格显示和表格结果外,所有历史记录。

我的页面是一个关于战斗的简单游戏,当用户点击刷新时,它不需要按下“战斗”按钮就可以继续战斗,他甚至可以点击浏览器按钮而无需点击“Escape”表单按钮。我如何在我的代码中更正此问题?但请记住,我已经包含了HTML页面,并且HTML页面上显示的内容就是这样:

<?php 
if(!$_POST and $poskodbe != '0') { ?>

<p>You are attacked<?php text($spol); ?> by <?php text($monster); ?> !</p>

<form action='../php/gozd.php' method='post'>
<input type='submit' name='action' value='Fight' /> ali 
<input type='submit' name='action' value='Escape' />
<input type='hidden' name='monster' value= '<?php text($monster); ?>' />
</form>

<?php } 

else { ?>
more HTML tags here etc... <?php } ?>

完整的代码编辑:

HTML:

<body>
    <?php if(!$_POST and $poskodbe != '0') { ?>
    <p>Presenetil<?php text($spol); ?> te je <?php text($monster); ?> !</p>
<form action='../php/gozd.php' method='post'>
    <input type='submit' name='action' value='Napadi' /> ali 
    <input type='submit' name='action' value='Pobegni' />
            <input type='hidden' name='monster' value= '<?php text($monster); ?>' />
</form>
    <?php } 

    else if ($poskodbe == '0'){echo $moznost; ?> 
    <p><a href='../php/start.php'>Odpravi se proti domu</a></p> 
    <?php } 

    else { ?>        
    <ul><?php foreach ($combat as $turns => $i) { ?>
        <li> <p><strong><?php text($i['napadalec']); ?></strong>
             <?php text(' napade '); ?><strong><?php text($i['branilec']); ?></strong>
             <?php text(' in mu napravi poškodbe za ') ?><strong><?php text($i['damage']); ?></strong>
             <?php text(' točk zdravja '); } ?> </p></li> 
    </ul>

    <?php if(isset ($zmaga)) { ?> 
    <p>Pregnal si <strong><?php text($monster_ime); ?></strong>! 
       V naglici je za seboj pustil <strong><?php text($cekini); ?></strong> cekinov, ki jih seveda pobereš.</p>
    <p><a href='../php/gozd.php'>Raziskuj dalje</a></p>
    <?php } ?>

    <?php if(isset ($zguba)) { ?>
    <p>Podlegel si poškodbam <strong><?php text($monster_ime); ?></strong>.</p>
    <?php } ?>

    <p><a href='../php/start.php'>Odpravi se proti domu</a></p>
    <?php } ?>        

</body>

</html>

PHP:

<?php

session_start();
include 'config.php';
include 'razno.php';
include 'stats.php';
$igralec_ime = $_SESSION['username'];
$poskodbe = prikazi_stat('curhp', $igralec_ime);

if ($poskodbe == '0') {$moznost = 'Tvoje zdravje je resno ogroženo, vrni se domov!';}
else {

if ($_POST) {   

if($_POST['action'] == 'Napadi') {

    $igralec = array (
                      'ime'         => $igralec_ime,
                      'napad'   => prikazi_stat('ofe',$igralec_ime),
                      'obramba' => prikazi_stat('def',$igralec_ime),
                      'curhp'       => prikazi_stat('curhp',$igralec_ime)
                     );

    $monster_ime = $_POST['monster'];
    $monster = array (
                      'ime'         => $monster_ime,
                      'napad'   => prikazi_monster_stat('ofe',$monster_ime),
                      'obramba' => prikazi_monster_stat('def',$monster_ime),
                      'curhp'       => prikazi_monster_stat('maxhp',$monster_ime)
                     );       

    $combat = array();
    $turns = 0;     
    while($igralec['curhp'] > 0 && $monster['curhp'] > 0) {


        if($turns % 2 != 0) {
            $napadalec = &$monster;
            $branilec = &$igralec; } 
        else {
            $napadalec = &$igralec;
            $branilec = &$monster; }


        $damage = 0;    
        if($napadalec['napad'] > $branilec['obramba']) {
            $damage = $napadalec['napad'] - $branilec['obramba']; }


        $branilec['curhp'] -= $damage;
        $combat[$turns] = array(
            'napadalec' =>  $napadalec['ime'],
            'branilec'  =>  $branilec['ime'],
            'damage'    =>  $damage
                               );

        $turns++; }


    update_stat('curhp',$igralec_ime,$igralec['curhp']);

    if($igralec['curhp'] > 0) {
        update_stat('cek',$igralec_ime,prikazi_stat('cek',$igralec_ime)+ prikazi_monster_stat('cek',$monster_ime)); 
        $zmaga = 1;
        $cekini = prikazi_monster_stat('cek',$monster_ime); }

    else {
    if ($igralec['curhp'] <0) {update_stat('curhp', $igralec_ime, '0'); }
    $zguba = 1; } }


else {
    header('Location:start.php'); } 


} 

else {

$query = sprintf("SELECT ime, spol FROM monsters ORDER BY RAND() LIMIT 1");
$result = mysql_query($query);
list($monster, $spol) = mysql_fetch_row($result); }

}   

include '../html/gozd.html';
?>

0 个答案:

没有答案