【发布时间】:2013-06-05 22:02:08
【问题描述】:
我正在创建一个网站,我正在尝试创建一个表单,将用户输入发送到我的谷歌文档/驱动器中的谷歌电子表格......我找到了一个 Github 项目,可以让人们编写 php ...它包括脚本所需的其他 2 个 php 文件。代码如下:
我的问题是,如何在 $u = / $p = 下隐藏我的密码? 任何查看代码的人都可以看到我的密码。我该如何防止这种情况发生?
脚本来源的链接是:http://www.farinspace.com/saving-form-data-to-google-spreadsheets/
<?php
// Zend library include path
set_include_path(get_include_path() . PATH_SEPARATOR . "$_SERVER[DOCUMENT_ROOT]/ZendGdata-1.8.1/library");
include_once("Google_Spreadsheet.php");
$u = "username@gmail.com";
$p = "password";
$ss = new Google_Spreadsheet($u,$p);
$ss->useSpreadsheet("My Spreadsheet");
$ss->useWorksheet("wks2");
// important:
// adding a leading alpha char prevents errors, there are issues
// when trying to lookup an identifier in a column where the
// value starts with both alpha and numeric characters, using a
// leading alpha character causes the column and its values to be
// seen as a strictly a strings/text
$id = "z" . md5(microtime(true));
$row = array
(
"id" => $id // used for later lookups
, "name" => "John Doe"
, "email" => "john@example.com"
, "comments" => "Hello world"
);
if ($ss->addRow($row)) echo "Form data successfully stored";
else echo "Error, unable to store data";
$row = array
(
"name" => "John Q Doe"
);
if ($ss->updateRow($row,"id=".$id)) echo "Form data successfully updated";
else echo "Error, unable to update spreadsheet data";
?>
【问题讨论】:
-
需要有一个用户可以访问您的文件。因此,您的密码将是可读的。不与任何人共享该用户或与任何人共享您的服务器怎么样?
-
为什么/如何有人会/可以阅读代码吗?如果它应该是安全的,请不要在代码中输入密码 - 就这么简单。
-
@BLaZuRE:访问用户是什么意思?电子表格将保存到“我的”谷歌文档帐户,所以帐户密码不应该是我自己的帐户密码吗?或者我也可以在谷歌文档上创建一个虚拟用户吗?喜欢雅虎邮件上的身份?