- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试运行一些代码。
代码可以在下一个链接中找到code link
如你所见,它有一个客户端和一个服务器代码,这段代码是一个基于套接字通信的android即时通讯工具。
服务器代码包含三个文件 - 一个 sql 文件和两个 php 文件。
问题是当我使用 XAMPP 作为本地主机测试代码时一切正常。
当我试图将它移动到服务器时,问题就开始了。
我所做的很简单 - 我在 serversfree.com 上开了一个帐户。然后我去了 MySQL 数据库并创建了一个数据库名称:和用户名。之后我上传了 sql 文件。
然后我转到文件管理器选项 - 并将 index.php 和 mysql.class.php 上传到它。而且我还在 index.php 文件中编辑了四个相关行 -
$dbHost = "";
$dbUsername = "DBUSERNAME";
$dbPassword = "DBPASSWORD";
$dbName = "DBNAME";
当然每行的输入与这里显示的不同。
问题是,例如,当用户尝试注册时 - 当我在本地主机上尝试时一切正常,但是对于服务器 - 在客户端它告诉用户出了点问题并且签名up 失败 - 但是当我查看 mySQL 表时,我可以看到用户信息确实进入了表,甚至我可以使用该用户信息登录。
我遇到的另一个问题是,当用户试图将另一个用户添加到他的联系人列表时 - 肯定似乎不起作用。即使当我转到 mySQL 表并将值从 0 更改为 1 - 就好像说好友请求已获批准 - 用户名仍然没有显示在好友列表中。那件事肯定在本地主机场景中有效。
好吧,我希望这里有人可以帮助我弄清楚是什么导致了这个问题。
这是我点击注册时 android 的 logcat -
03-05 15:48:20.834: D/SSRMv2:Monitor(2346): SIOP:: AP = 300, Prev AP = 300, Duration = 10002
03-05 15:48:21.214: I/InputReader(2346): Touch event's action is 0x0 (deviceType=0) [pCnt=1, s=0.13493 ] when=137349122712000
03-05 15:48:21.214: I/InputDispatcher(2346): Delivering touch to: action: 0x0
03-05 15:48:21.269: D/STATUSBAR-NetworkController(31809): refreshSignalCluster: data=-1 bt=false
03-05 15:48:21.284: D/STATUSBAR-IconMerger(31809): checkOverflow(384), More:false, Req:false Child:2
03-05 15:48:21.359: I/InputReader(2346): Touch event's action is 0x1 (deviceType=0) [pCnt=1, s=] when=137349265664000
03-05 15:48:21.359: I/InputDispatcher(2346): Delivering touch to: action: 0x1
03-05 15:48:21.359: E/DatabaseUtils(2346): Writing exception to parcel
03-05 15:48:21.359: E/DatabaseUtils(2346): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
03-05 15:48:21.359: E/DatabaseUtils(2346): at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
03-05 15:48:21.359: E/DatabaseUtils(2346): at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
03-05 15:48:21.359: E/DatabaseUtils(2346): at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
03-05 15:48:21.359: E/DatabaseUtils(2346): at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
03-05 15:48:21.359: E/DatabaseUtils(2346): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
03-05 15:48:21.359: E/DatabaseUtils(2346): at android.os.Binder.execTransact(Binder.java:388)
03-05 15:48:21.359: E/DatabaseUtils(2346): at dalvik.system.NativeStart.run(Native Method)
03-05 15:48:21.359: W/ActivityManager(2346): Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
03-05 15:48:21.379: V/WindowManager(2346): Window{42eec348 u0 Keyguard}mOrientationRequetedFromKeyguard=false
03-05 15:48:21.399: I/SurfaceFlinger(1935): id=5600 createSurf (1x1),1 flag=4, Uoast
03-05 15:48:21.399: V/WindowManager(2346): Window{42eec348 u0 Keyguard}mOrientationRequetedFromKeyguard=false
03-05 15:48:21.419: D/PowerManagerService(2346): [api] acquire WakeLock flags=0x2000000a tag=WindowManager uid=1000 pid=2346
03-05 15:48:22.274: D/STATUSBAR-NetworkController(31809): refreshSignalCluster: data=-1 bt=false
03-05 15:48:22.284: D/STATUSBAR-IconMerger(31809): checkOverflow(384), More:false, Req:false Child:2
03-05 15:48:22.879: D/SensorService(2346): 1.9 4.0 8.4
03-05 15:48:23.284: D/STATUSBAR-NetworkController(31809): refreshSignalCluster: data=-1 bt=false
03-05 15:48:23.299: D/STATUSBAR-IconMerger(31809): checkOverflow(384), More:false, Req:false Child:2
03-05 15:48:23.329: D/SSRMv2:Monitor(2346): SIOP:: AP = 300 (read only)
03-05 15:48:23.554: D/dalvikvm(2346): GC_CONCURRENT freed 1476K, 18% free 47668K/57704K, paused 10ms+13ms, total 227ms
03-05 15:48:24.294: D/STATUSBAR-NetworkController(31809): refreshSignalCluster: data=-1 bt=false
03-05 15:48:24.304: D/STATUSBAR-IconMerger(31809): checkOverflow(384), More:false, Req:false Child:2
03-05 15:48:25.294: D/STATUSBAR-NetworkController(31809): refreshSignalCluster: data=-1 bt=false
03-05 15:48:25.299: D/STATUSBAR-IconMerger(31809): checkOverflow(384), More:false, Req:false Child:2
03-05 15:48:25.419: I/SurfaceFlinger(1935): id=5600 Removed Uoast (5/5)
03-05 15:48:25.419: I/SurfaceFlinger(1935): id=5600 Removed Uoast (-2/5)
03-05 15:48:25.424: D/PowerManagerService(2346): [api] [s] userActivity : event: 0 flags: 0 (uid: 1000 pid: 2346)
03-05 15:48:25.429: D/PowerManagerService(2346): [api] release WakeLock flags=0x2000000a tag=WindowManager uid=1000 pid=2346 (0x0)
03-05 15:48:25.429: D/PowerManagerService(2346): [api] applyWakeLockFlagsOnReleaseLocked : userActivityNoUpdateLocked is called : SCREEN_BRIGHT_WAKE_LOCK 'WindowManager' ON_AFTER_RELEASE (uid=1000, pid=2346, ws=WorkSource{10161}) (elapsedTime=4012)
这是每个 php 文件的代码-
index.php - 代码:
<?php
/****************************************
* Server of Android IM Application
*
* Supported actions:
* 1. authenticateUser
* if user is authentiated return friend list
*
* 2. signUpUser
*
* 3. addNewFriend
*
* 4. responseOfFriendReqs
*
* 5. testWebAPI
*************************************/
//TODO: show error off
require_once("mysql.class.php");
$dbHost = "localhost";
$dbUsername = "DBUSERNAME";
$dbPassword = "DBPASSWORD";
$dbName = "DBNAME";
$db = new MySQL($dbHost,$dbUsername,$dbPassword,$dbName);
// if operation is failed by unknown reason
define("FAILED", 0);
define("SUCCESSFUL", 1);
// when signing up, if username is already taken, return this error
define("SIGN_UP_USERNAME_CRASHED", 2);
// when add new friend request, if friend is not found, return this error
define("ADD_NEW_USERNAME_NOT_FOUND", 2);
// TIME_INTERVAL_FOR_USER_STATUS: if last authentication time of user is older
// than NOW - TIME_INTERVAL_FOR_USER_STATUS, then user is considered offline
define("TIME_INTERVAL_FOR_USER_STATUS", 60);
define("USER_APPROVED", 1);
define("USER_UNAPPROVED", 0);
$username = (isset($_REQUEST['username']) && count($_REQUEST['username']) > 0)
? $_REQUEST['username']
: NULL;
$password = isset($_REQUEST['password']) ? md5($_REQUEST['password']) : NULL;
$port = isset($_REQUEST['port']) ? $_REQUEST['port'] : NULL;
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : NULL;
if ($action == "testWebAPI")
{
if ($db->testconnection()){
echo SUCCESSFUL;
exit;
}else{
echo FAILED;
exit;
}
}
if ($username == NULL || $password == NULL)
{
echo FAILED;
exit;
}
$out = NULL;
error_log($action."\r\n", 3, "error.log");
switch($action)
{
case "authenticateUser":
if ($userId = authenticateUser($db, $username, $password))
{
// providerId and requestId is Id of a friend pair,
// providerId is the Id of making first friend request
// requestId is the Id of the friend approved the friend request made by providerId
// fetching friends,
// left join exp<b></b>ression is a bit different,
// it is required to fetch the friend, not the users itself
$sql = "select u.Id, u.username, (NOW()-u.authenticationTime) as authenticateTimeDifference, u.IP,
f.providerId, f.requestId, f.status, u.port
from friends f
left join users u on
u.Id = if ( f.providerId = ".$userId.", f.requestId, f.providerId )
where (f.providerId = ".$userId." and f.status=".USER_APPROVED.") or
f.requestId = ".$userId." ";
//$sqlmessage = "SELECT * FROM `messages` WHERE `touid` = ".$userId." AND `read` = 0 LIMIT 0, 30 ";
$sqlmessage = "SELECT m.id, m.fromuid, m.touid, m.sentdt, m.read, m.readdt, m.messagetext, u.username from messages m \n"
. "left join users u on u.Id = m.fromuid WHERE `touid` = ".$userId." AND `read` = 0 LIMIT 0, 30 ";
if ($result = $db->query($sql))
{
$out .= "<data>";
$out .= "<user userKey='".$userId."' />";
while ($row = $db->fetchObject($result))
{
$status = "offline";
if (((int)$row->status) == USER_UNAPPROVED)
{
$status = "unApproved";
}
else if (((int)$row->authenticateTimeDifference) < TIME_INTERVAL_FOR_USER_STATUS)
{
$status = "online";
}
$out .= "<friend username = '".$row->username."' status='".$status."' IP='".$row->IP."' userKey = '".$row->Id."' port='".$row->port."'/>";
// to increase security, we need to change userKey periodically and pay more attention
// receiving message and sending message
}
if ($resultmessage = $db->query($sqlmessage))
{
while ($rowmessage = $db->fetchObject($resultmessage))
{
$out .= "<message from='".$rowmessage->username."' sendt='".$rowmessage->sentdt."' text='".$rowmessage->messagetext."' />";
$sqlendmsg = "UPDATE `messages` SET `read` = 1, `readdt` = '".DATE("Y-m-d H:i")."' WHERE `messages`.`id` = ".$rowmessage->id.";";
$db->query($sqlendmsg);
}
}
$out .= "</data>";
}
else
{
$out = FAILED;
}
}
else
{
// exit application if not authenticated user
$out = FAILED;
}
break;
case "signUpUser":
if (isset($_REQUEST['email']))
{
$email = $_REQUEST['email'];
$sql = "select Id from users
where username = '".$username."' limit 1";
if ($result = $db->query($sql))
{
if ($db->numRows($result) == 0)
{
$sql = "insert into users(username, password, email)
values ('".$username."', '".$password."', '".$email."') ";
error_log("$sql", 3 , "error_log");
if ($db->query($sql))
{
$out = SUCCESSFUL;
}
else {
$out = FAILED;
}
}
else
{
$out = SIGN_UP_USERNAME_CRASHED;
}
}
}
else
{
$out = FAILED;
}
break;
case "sendMessage":
if ($userId = authenticateUser($db, $username, $password))
{
if (isset($_REQUEST['to']))
{
$tousername = $_REQUEST['to'];
$message = $_REQUEST['message'];
$sqlto = "select Id from users where username = '".$tousername."' limit 1";
if ($resultto = $db->query($sqlto))
{
while ($rowto = $db->fetchObject($resultto))
{
$uto = $rowto->Id;
}
$sql22 = "INSERT INTO `messages` (`fromuid`, `touid`, `sentdt`, `messagetext`) VALUES ('".$userId."', '".$uto."', '".DATE("Y-m-d H:i")."', '".$message."');";
error_log("$sql22", 3 , "error_log");
if ($db->query($sql22))
{
$out = SUCCESSFUL;
}
else {
$out = FAILED;
}
$resultto = NULL;
}
$sqlto = NULL;
}
}
else
{
$out = FAILED;
}
break;
case "addNewFriend":
$userId = authenticateUser($db, $username, $password);
if ($userId != NULL)
{
if (isset($_REQUEST['friendUserName']))
{
$friendUserName = $_REQUEST['friendUserName'];
$sql = "select Id from users
where username='".$friendUserName."'
limit 1";
if ($result = $db->query($sql))
{
if ($row = $db->fetchObject($result))
{
$requestId = $row->Id;
if ($row->Id != $userId)
{
$sql = "insert into friends(providerId, requestId, status)
values(".$userId.", ".$requestId.", ".USER_UNAPPROVED.")";
if ($db->query($sql))
{
$out = SUCCESSFUL;
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED; // user add itself as a friend
}
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED;
}
break;
case "responseOfFriendReqs":
$userId = authenticateUser($db, $username, $password);
if ($userId != NULL)
{
$sqlApprove = NULL;
$sqlDiscard = NULL;
if (isset($_REQUEST['approvedFriends']))
{
$friendNames = split(",", $_REQUEST['approvedFriends']);
$friendCount = count($friendNames);
$friendNamesQueryPart = NULL;
for ($i = 0; $i < $friendCount; $i++)
{
if (strlen($friendNames[$i]) > 0)
{
if ($i > 0 )
{
$friendNamesQueryPart .= ",";
}
$friendNamesQueryPart .= "'".$friendNames[$i]."'";
}
}
if ($friendNamesQueryPart != NULL)
{
$sqlApprove = "update friends set status = ".USER_APPROVED."
where requestId = ".$userId." and
providerId in (select Id from users where username in (".$friendNamesQueryPart."));
";
}
}
if (isset($_REQUEST['discardedFriends']))
{
$friendNames = split(",", $_REQUEST['discardedFriends']);
$friendCount = count($friendNames);
$friendNamesQueryPart = NULL;
for ($i = 0; $i < $friendCount; $i++)
{
if (strlen($friendNames[$i]) > 0)
{
if ($i > 0 )
{
$friendNamesQueryPart .= ",";
}
$friendNamesQueryPart .= "'".$friendNames[$i]."'";
}
}
if ($friendNamesQueryPart != NULL)
{
$sqlDiscard = "delete from friends
where requestId = ".$userId." and
providerId in (select Id from users where username in (".$friendNamesQueryPart."));
";
}
}
if ( ($sqlApprove != NULL ? $db->query($sqlApprove) : true) &&
($sqlDiscard != NULL ? $db->query($sqlDiscard) : true)
)
{
$out = SUCCESSFUL;
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED;
}
break;
default:
$out = FAILED;
break;
}
echo $out;
///////////////////////////////////////////////////////////////
function authenticateUser($db, $username, $password)
{
$sql22 = "select * from users
where username = '".$username."' and password = '".$password."'
limit 1";
$out = NULL;
if ($result22 = $db->query($sql22))
{
if ($row22 = $db->fetchObject($result22))
{
$out = $row22->Id;
$sql22 = "update users set authenticationTime = NOW(),
IP = '".$_SERVER["REMOTE_ADDR"]."' ,
port = 15145
where Id = ".$row22->Id."
limit 1";
$db->query($sql22);
}
}
return $out;
}
?>
mysql.class.php - 代码:
<?php
class MySQL
{
private $dbLink;
private $dbHost;
private $dbUsername;
private $dbPassword;
private $dbName;
public $queryCount;
function MySQL($dbHost,$dbUsername,$dbPassword,$dbName)
{
$this->dbHost = $dbHost;
$this->dbUsername = $dbUsername;
$this->dbPassword = $dbPassword;
$this->dbName = $dbName;
$this->queryCount = 0;
}
function __destruct()
{
$this->close();
}
//connect to database
private function connect() {
$this->dbLink = mysql_connect($this->dbHost, $this->dbUsername, $this->dbPassword);
if (!$this->dbLink) {
$this->ShowError();
return false;
}
else if (!mysql_select_db($this->dbName,$this->dbLink)) {
$this->ShowError();
return false;
}
else {
mysql_query("set names latin5",$this->dbLink);
return true;
}
unset ($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);
}
/*****************************
* Method to close connection *
*****************************/
function close()
{
@mysql_close($this->dbLink);
}
/*******************************************
* Checks for MySQL Errors
* If error exists show it and return false
* else return true
*******************************************/
function ShowError()
{
$error = mysql_error();
//echo $error;
}
/****************************
* Method to run SQL queries
****************************/
function query($sql)
{
if (!$this->dbLink)
$this->connect();
if (! $result = mysql_query($sql,$this->dbLink)) {
$this->ShowError();
return false;
}
$this->queryCount++;
return $result;
}
/************************
* Method to fetch values*
*************************/
function fetchObject($result)
{
if (!$Object=mysql_fetch_object($result))
{
$this->ShowError();
return false;
}
else
{
return $Object;
}
}
/*************************
* Method to number of rows
**************************/
function numRows($result)
{
if (false === ($num = mysql_num_rows($result))) {
$this->ShowError();
return -1;
}
return $num;
}
/*******************************
* Method to safely escape strings
*********************************/
function escapeString($string)
{
if (get_magic_quotes_gpc())
{
return $string;
}
else
{
$string = mysql_escape_string($string);
return $string;
}
}
function free($result)
{
if (mysql_free_result($result)) {
$this->ShowError();
return false;
}
return true;
}
function lastInsertId()
{
return mysql_insert_id($this->dbLink);
}
function getUniqueField($sql)
{
$row = mysql_fetch_row($this->query($sql));
return $row[0];
}
function testconnection() {
$this->dbLink = mysql_connect($this->dbHost, $this->dbUsername, $this->dbPassword);
if (!$this->dbLink) {
$this->ShowError();
return false;
}
else if (!mysql_select_db($this->dbName,$this->dbLink)) {
$this->ShowError();
return false;
}
else {
mysql_query("set names latin5",$this->dbLink);
return true;
}
unset ($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);
}
}
最佳答案
我们发现问题似乎是像 serversfree.com 或 000webhost.com 这样的免费托管网站正在向代码中添加分析代码。
所以要克服这个 - 000webhost 的解决方案如下 -
在文件管理器中,您需要在 [public_html] 中创建一个名为 [.htaccess] 的文件在里面你需要输入 -
<FilesMatch "\.(php)$">
php_value auto_append_file none
</FilesMatch>
这将防止所有 .php 文件附加分析代码。只需将 [php] 替换为您希望删除分析代码的任何文件扩展名即可。
为了防止您的域被取消,请不要通过转到下一个链接 - http://members.000webhost.com/analytics.php 来禁用您的分析代码。
编辑 -这也适用于serverfree.com
关于php - 设置从本地主机到服务器的服务器代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22198912/
这个问题已经有答案了: Is there any way to accept only numeric values in a JTextField? (20 个回答) It's possible i
我使用戴尔 XPS M1710。笔记本电脑的盖子、侧面扬声器和前置扬声器都有灯(3 组灯可以单独调节)和鼠标垫下方的灯。在 BIOS 中,我可以更改这些灯的颜色,至少是每个组。另外,我可以在鼠标垫下打
我知道我可以使用 在 iOS 5 中打开设置应用 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"
我有一个 Django 应用程序,我正在尝试为其设置文档。目录结构如下: - doc - project | - manage.py 我已经设置了路径以便 Sphinx 可以看到东西,但是当我尝试使用
我正在使用 768mb ram 运行 centos 5.5。我一直在日志中获取 server reached MaxClients setting, consider raising the MaxC
我在具有以下配置的服务器内运行了 Drupal 安装: StartServers 5 MinSpareServers 5 MaxSpareServers 15 MaxClien
是否可以使用 Microsoft.Web.Administration 包为给定的 location 配置 asp 设置? 我想以编程方式将以下部分添加到本地 IIS applicationHost.
我一直在阅读为 kube-proxy 提供参数的文档,但没有解释应该如何使用这些参数。我使用 az aks create 创建我的集群使用 azure-cli 程序,然后我获得凭据并使用 kubect
我想知道与在 PHP 中使用 setcookie() 函数相比,在客户端通过 JavaScript 设置一些 cookie 是否有任何明显的优势?我能想到的唯一原因是减少一些网络流量(第一次)。但不是
我有一个按钮可以将 body class 设置为 .blackout 我正在使用 js-cookie设置cookie,下面的代码与我的按钮相关联。 $('#boToggle').on('click'
我有一堆自定义的 HTML div。我将其中的 3 存储在具有 slide 类的 div 中。然后,我使用该幻灯片类调用 slick 函数并应用如下设置: $('.slide').slick({
我正在创建一个应该在 Windows 8(桌面)上运行的应用 我需要: 允许用户使用我的应用启动“文件历史记录”。我需要找到打开“文件历史记录”的命令行。 我需要能够显示“文件历史记录”的当前设置。
我刚买了一台新的 MacBook Pro,并尝试在系统中设置 RVM。我安装了 RVM 并将默认设置为 ➜ rvm list default Default Ruby (for new shells)
由于有关 Firestore 中时间戳行为即将发生变化的警告,我正在尝试更改我的应用的初始化代码。 The behavior for Date objects stored in Firestore
在 ICS 中,网络 -> 数据使用设置屏幕中现在有“限制后台数据”设置。 有没有办法以编程方式为我的应用程序设置“限制后台数据”? 或 有没有办法为我的应用程序调出具有选项的“数据使用”设置? 最佳
我正在尝试使用 NextJS 应用程序设置 Jest,目前在 jest.config.js : module.exports = { testPathIgnorePatterns: ["/.n
我最近升级到 FlashDevelop 4,这当然已经将我之前的所有设置恢复到原来的状态。 我遇到的问题是我无法在新设置窗口的哪个位置找到关闭它在方括号、大括号等之前插入的自动空格的选项。 即它会自动
有没有办法以编程方式访问 iPhone/iPod touch 设置? 谢谢。比兰奇 最佳答案 大多数用户设置可以通过读取存储在 /User/Library/Preferences/ 中的属性列表来访问
删除某些值时,我需要选择哪些设置来维护有序队列。我创建了带有自动增量和主键的 id 的表。当我第一次插入值时,没问题。就像 1,2,3,4,5... 当删除某些值时,顺序会发生变化,例如 1,5,3.
我正在尝试设置示例 Symfony2 项目,如此处所示 http://symfony.com/doc/current/quick_tour/the_big_picture.html 在访问 confi
我是一名优秀的程序员,十分优秀!