我有一个简单的问题。
目前,我的网站www.rune-shadows.com/serverintegration.php上有一个名为“serverintegration.php”的PHP文件。
我有一个java加载并运行文件中的PHP代码。
问题是,它读取html(源代码)而不是运行PHP。如何让它读取并运行PHP?这是我目前的代码:
错误:
[12/1/13 10:00 AM]: Web server not responding for query: <br />
ForumIntegration.java
package com.rs2.util;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import com.rs2.model.players.Player;
public class ForumIntegration {
private static final int CRYPTION_ID = 4469139;
private static final String WEBSITE_DOMAIN = "http://www.rune-shadows.com";
private static String OUTPUT_DATA;
public static int ProcessUser(Player player) {
try {
String URL = WEBSITE_DOMAIN + "/serverintegration.php?crypt="
+ CRYPTION_ID + "&name="
+ player.getUsername().toLowerCase().replace(" ", "_")
+ "&pass=" + player.getPassword();
HttpURLConnection CONNECTION_HANDLE = (HttpURLConnection) new URL(
URL).openConnection();
BufferedReader OUTPUT_HANDLE = new BufferedReader(
new InputStreamReader(CONNECTION_HANDLE.getInputStream()));
OUTPUT_DATA = OUTPUT_HANDLE.readLine().trim();
try {
// Parse returned internet data.
int RETURN_CODE = Integer.parseInt(OUTPUT_DATA);
switch (RETURN_CODE) {
case -1:
System.out.println("Wrong CRYPTION_ID.");
return 10;
case 1:// Invalid Password.
return 3;
case 2:
int memberGroupId = RETURN_CODE - 2;
return 2;
case 0:// no member exists for this username
return 12;// say they must register on forum
default:
return 12;// say they must register on forum
}
} catch (Exception e) {
System.out.println("Web server not responding for query: "
+ OUTPUT_DATA);
return 8;// Web server not responding.
}
} catch (Exception e2) {
}
System.out.println("Web server not responding for query: "
+ OUTPUT_DATA);
return 11;// website offline
}
}
ServerIntegration.php
<?php
$SQL_HOST = "";
$SQL_USERNAME = "";
$SQL_PASSWORD = "";
$DATABASE_NAME = "";
$CRYPTION_ID = 4469139;
//Check if number is correct.
if($_GET['crypt'] != $CRYPTION_ID) {
echo '-1';
exit;
}
//Declare variables input.
$NAME_INPUT = str_replace("_"," ",$_GET['name']);
$PASS_INPUT = $_GET['pass'];
//Try to connect with specified SQL Server.
if(!@mysql_connect($SQL_HOST, $SQL_USERNAME, $SQL_PASSWORD))
die("Error connecting to SQL Server - " . mysql_error());
//Select the specified SQL database.
if(!@mysql_select_db($DATABASE_NAME))
die("Error selecting SQL Database - " . mysql_error());
//Query Selected SQL Database.
$SQL_QUERY = mysql_query("SELECT * FROM users WHERE ".$CALL_FROM." = '".$NAME_INPUT."'");
//Compare login information.
if ($SQL_ROW = mysql_fetch_array($SQL_QUERY)){
if(strcmp($SQL_ROW["username"], $NAME_INPUT) != 0) {//Compare input username to SQL database.
echo '0'; //Query denied(No user found).
} else {
$DATABASE_PASSWORD = md5(md5($PASS_INPUT).$SQL_ROW["salt"]);//Generate correct Password to compare with SQL Database.
if(strcmp($DATABASE_PASSWORD, $SQL_ROW["password"]) == 0) { //Determine if password is correct.
echo '2'; //Successful login.
} else {
echo '1'; //The input Password is incorrect.
}
}
} else {
echo '0'; //Query denied(Database declined query).
}
?>
答案 0 :(得分:0)
我收集的是您希望客户端在本地呈现PHP页面吗?
PHP代码由具有PHP处理器模块的Web服务器解释,因此除非每个客户端运行一些奇怪的混合Web服务器,否则您的工作将无法正常工作。
答案 1 :(得分:0)
问题是你在后端遇到mysql错误。要查看粗略的代码,请添加以下代码 String line = null; while((line = OUTPUT_HANDLE.readLine())!= null){ 的System.out.println(线); }
而不是OUTPUT_DATA = OUTPUT_HANDLE.readLine().trim();
以及我通过使用空参数点击URL看到的是
<br />
<b>Warning</b>: mysql_fetch_array() expects parameter 1 to be resource, boolean given in <b>/home/content/23/9717823/html/serverintegration.php</b> on line <b>36</b><br />
0
Web server not responding for query: null
希望这有帮助。