dscqrkvr9562034621 2013-12-01 15:13
浏览 61

使用Java读取外部PHP文件

I have a quick question.

Currently I have a PHP file named "serverintegration.php" located on my website at www.rune-shadows.com/serverintegration.php .

I have a java that loads and runs the PHP code in the file.

The issue is, it reads the html (the source code) rather than running the PHP. How do I make it read and run the PHP? Here is my current code:

Error:

[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).
}
?>
  • 写回答

2条回答 默认 最新

  • dongpan3001 2013-12-01 15:28
    关注

    What I gather is that you want the client to render the PHP page locally?

    PHP code is interpreted by a web server with a PHP processor module, so unless each client is running some bizarre hybrid web server what your doing isn't going to work.

    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了