English 中文(简体)
为什么我列入的档案在出现时再次被处死?
原标题:Why is my included file executed again when isset(POST[ submit ])?

我的档案(包括:php)就是:

<?php
$myarray=(a,b,c);
shuffle($myarray);
?>

我的主要文件是:

include( include.php );

if isset($_POST[ submit_button ]){
      echo "Button was clicked";
      echo $myarray;
      }
else {
     echo "Not clicked."; 
     echo $myarray;
     }
?>

<form method= POST ><input type= submit  name= submit_button ></form>

在我点击 but子后,为什么按不同顺序展示了<代码>$myarray的内容? 难道说它只是一次uff倒吗?

我怎么能防止le子被处死不止一次? (因此,我可以按同样顺序在提点之前和之后显示我的传闻内容)

最佳回答

每一次都会对你的PHP档案进行解释。 现在,你们的系统没有记忆,因此,你们的档案无法“拯救”这些阵列已经uff。 此外,如果你一度填充阵列,然后又第二次装上该页,并管理not,使之窒息,则阵列将是(a,b,c),因为变数先入(a,b,c),永远不会被uff。

如果我理解正确的话,你可以使用会议。

$myarray=(a,b,c);

if (!isset($_SESSION[ shuffled ])) {
    shuffle($myarray);
    $_SESSION[ shuffled ] = $myarray;
} else {
    $myarray = $_SESSION[ shuffled ];
}
问题回答

之所以出现这种情况,是因为每当你装上该页时,该档案就被列入其中,而且该档案也再次填满了阵列。

采用<代码>射入(),然后按照你的意愿使用POST阵列。 采用<代码>unserialize()

http://www.php.net/manual/en/Function.serialize.php





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签