Jump to content

Passing URL via POST splitting into many parts


freelance84

Recommended Posts

Trying to grasp some more of the basics here...

I have a simple script that will pass the value of a text box back to the server via AJAX.

 

Upon testing the simple script i found that if i sent a long URL (like from google) with lots of different things in its GET... the php receives the said URL split into lots of different params:

 

Going in: http://www.google.co.uk/#sclient=psy&hl=en&site=&source=hp&q=a+site&aq=f&aqi=&aql=&oq=&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=ab90aaaebdbbd579&biw=1680&bih=909

 

The JS:

/*saving ther new URL*/
function saveURL(){
var newURL = document.getElementById('newURL').value;

alert(newURL);//This alerts the full URL

/*setting the variables*/
var url = "http://www.asite.net/mymarksProcessor.php";
var params = "newURL="+newURL;

alert(params);//This alerts the full URL

/*xml connection*/
xmlsetup();

xmlhttp.open("POST", url, true);

/*Send the proper header information along with the request*/
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange = function() {
	if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var response = xmlhttp.responseText;
		alert(response);
	}
}
xmlhttp.send(params);
}

 

The php:

elseif(!empty($_POST))
{
	if(isset($_POST['newURL']))
		{
			$newURL = mysql_real_escape_string(htmlentities($_POST['newURL']));
			print_r($_POST);
			exit();

 

 

The Result from the the print_r($_POST) =

Array

(

    [newURL] => http://www.google.co.uk/#sclient=psy

    [hl] => en

    [site] =>

    [source] => hp

    [q] => a site

    [aq] => f

    [aqi] =>

    [aql] =>

    [oq] =>

    [pbx] => 1

    [bav] => on.2,or.r_gc.r_pw.

    [fp] => ab90aaaebdbbd579

    [biw] => 1680

    [bih] => 909

)

 

 

Really not sure what's going on here. Does anyone know why the var params = "newURL="+newURL; is being split at every & sign??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.