【问题标题】:How to send info from two session variable to a text file if a number has been guessed [closed]如果数字已被猜到,如何将信息从两个会话变量发送到文本文件[关闭]
【发布时间】:2019-04-03 00:04:25
【问题描述】:

我被困住了,我很乐意得到一些指导。

我需要将同一会话中两个会话变量的信息发送到一个文本文件。

猜测次数: $_SESSION['antal_gaet']

用户名: $_SESSION['username']

如何写入文本文件,以便可以使用(猜测次数、用户名)从数组中创建高分列表。

感谢您提供的任何帮助。

【问题讨论】:

标签: php arrays file session session-variables


【解决方案1】:

您可以创建/打开一个新文件,然后在其中写入变量的串联:

$scores_file = 'scores.txt';
// open the file
$handle = fopen($scores_file, 'w') or die('Cannot open file:  '.$scores_file);
// create 1rst line and a line feed \n
$data = 'Number of guesses:'.$_SESSION['antal_gaet']."\n";
// concat the 2nd line
$data .= 'Username:'.$_SESSION['username'];
// write to the opened file
fwrite($handle, $data);

【讨论】:

  • 旁注:"我借此机会修复了一个明显的错误。单引号中的\n不会解析;它需要双引号。请下次小心,谢谢。 " - 是我在编辑时留下的注释。
猜你喜欢
  • 1970-01-01
  • 2018-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多