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??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.