ไม่พบวัตถุ PHP QueryString 404

ฉันเป็นนักพัฒนา Android ที่มีความรู้เกี่ยวกับ PHP น้อยมาก ฉันติดอยู่กับปัญหาในการรับ 404 Error Object Not Found เมื่ออ่านตัวแปรจากสตริงการสืบค้น ฉันเพิ่มไฟล์ .htaccess เนื่องจากข้อผิดพลาดหายไปแต่ตัวแปรไม่ได้รับการอ่าน แม้ว่าฉันจะอ่าน URL โดยไม่มีสตริงการสืบค้น มันก็ทำงานได้อย่างสมบูรณ์ ฉันไม่สามารถคิดถึงเหตุผลที่ไม่ควรทำงาน นี่คือสิ่งที่ฉันได้ลอง:

ไฟล์ PHP:

ชื่อไฟล์: file_getTest.php

function file_get_contents_curl($url) {
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}
$baseUrl='http://xyz.com?language=en';
$language = $_GET['language'];
$session = $_GET['sessionID'];
$placeOrigin=$_GET['place_origin'];
$typeOrigin=$_GET['type_origin']; 
$nameOrigin=$_GET['name_origin'];
$homePage =($baseUrl."&sessionID=".$session."&place_origin=".$placeOrigin."&type_origin=".$typeOrigin."&name_origin=".$nameOrigin);

//if "echo file_get_contents($baseUrl)" is executed it works fine

//echo file_get_contents($homePage); //I have tried file_get_contents but no use

echo file_get_contents_curl($homePage);

รหัส .htaccess:

RewriteEngine on
RewriteRule .* file_getTest.php

หากไม่มีไฟล์ .htacess และใช้ curl() ฉันได้รับข้อผิดพลาดนี้:

URL ที่ร้องขอ /test/file_getTest.php&sessionID=value read&place_origin=value read&type_origin=value read&name_origin=value read ไม่พบ strong> บนเซิร์ฟเวอร์นี้

ด้วยไฟล์ .htaccess และใช้ curl() ฉันได้รับข้อผิดพลาดต่อไปนี้:

ไม่พบวัตถุ HTTP/1.1 404

หากไม่มีไฟล์ .htacess และใช้ file_get_contents() ฉันได้รับข้อผิดพลาดนี้:

URL ที่ร้องขอ /test/file_getTest.php&sessionID=value read&place_origin=value read&type_origin=value read&name_origin=value read ไม่พบ strong> บนเซิร์ฟเวอร์นี้

ด้วยไฟล์ .htaccess & การใช้ file_get_contents() ฉันได้รับข้อผิดพลาดต่อไปนี้:

file_get_contents(http://xyz.com?language=en&sessionID=&place_origin=&type_origin=&name_origin=): ไม่สามารถเปิดสตรีม: คำขอ HTTP ล้มเหลว! ไม่พบวัตถุ HTTP/1.1 404 ใน C:\wamp\www\file_getTest.php ออนไลน์ 20

ฉันขอขอบคุณความช่วยเหลือใด ๆ มาก ฉันติดอยู่กับปัญหานี้มาระยะหนึ่งแล้ว & ดูเหมือนจะไม่สามารถหาวิธีแก้ไขได้


person Khan    schedule 07.02.2013    source แหล่งที่มา
comment
นั่นคือเหตุผลที่ฉันติดอยู่ ฉันดูเหมือนจะไม่พบข้อผิดพลาด แต่ขอบคุณสำหรับข้อมูลของคุณ   -  person Khan    schedule 07.02.2013
comment
URL ที่ถูกเฟรมทำงานอย่างอิสระในเว็บเบราว์เซอร์หรือไม่ คุณต้องตรวจสอบความถูกต้องของพารามิเตอร์ $_GET เหล่านั้น   -  person SparKot    schedule 07.02.2013
comment
ใช่แล้ว URL ทำงานได้ดี ไม่มีอะไรผิดปกติรวมถึงพารามิเตอร์ในสตริงการสืบค้นด้วย   -  person Khan    schedule 07.02.2013
comment
คุณสามารถเข้าถึงพูด google.com จาก PHP ได้ไหม ตรวจสอบการกำหนดค่าแล้ว   -  person SparKot    schedule 07.02.2013
comment
ใช่ทำงานได้ดี ฉันไม่มีปัญหาในการเข้าถึง URL แบบคงที่ ฉันมีปัญหาเมื่อพูดถึงการรับพารามิเตอร์   -  person Khan    schedule 07.02.2013


คำตอบ (1)


ปัญหาได้รับการแก้ไขแล้ว ดูเหมือนค่อนข้างแปลก แต่สิ่งที่ฉันทำคือสลับเครื่องหมายคำพูดคู่ "" ใน $homepage ด้วยเครื่องหมายคำพูดเดี่ยวในตัวแปรที่เหลือ หลังจากนั้น ฉันเข้ารหัสพารามิเตอร์สตริงการสืบค้นทั้งหมด & มันใช้งานได้อย่างมีเสน่ห์

รหัสสุดท้ายจึงมีลักษณะดังนี้:

$baseUrl="http://xyz.com?language=en";

$session = $_GET["sessionID"];
$placeOrigin=$_GET["place_origin"];
$typeOrigin=$_GET["type_origin"]; 
$nameOrigin=$_GET["name_origin"];

$placeDestination=$_GET["place_destination"];
$typeDestination=$_GET["type_destination"];
$nameDestination=$_GET["name_destination"];

$sessionE=urlencode($session);
$placeOriginE=urlencode($placeOrigin);
$typeOriginE=urlencode($typeOrigin);
$nameOriginE=urlencode($nameOrigin);

$placeDestinationE=urlencode($placeDestination);
$typeDestinationE=urlencode($typeDestination);
$nameDestinationE=urlencode($nameDestination);

$homepage=$baseUrl.'&sessionID='.$sessionE.'&place_origin='.$placeOriginE.'&type_origin='.$typeOriginE.'&name_origin='.$nameOriginE.'&place_destination='.$placeDestinationE.'&type_destination='.$typeDestinationE.'&name_destination='.$nameDestinationE;
person Khan    schedule 21.02.2013