Page 1 of 1

XMLHttpRequest in php help

Posted: Sun Aug 03, 2008 8:52 am
by yuri1992
hello to all.
who i do XMLHttpRequest in php ?
i need to send to some server a data with XMLHttpRequest
the send me code in ASP

Code: Select all

 
 Set oHttp = CreateObject("Microsoft.XMLHTTP") 
oHttp.open "POST", "http://www.someurl.co.il/", False
oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHttp.send "var1=" & somever1 & "&var2=" & somever2
SendData = oHttp.responseText
set oHttp = nothing
but i work in php
some can give me a exp to XMLHttpRequest in php ?

Re: XMLHttpRequest in php help

Posted: Sun Aug 03, 2008 9:47 am
by pkbruker
Don't use XMLHTTPRequest if you're working with PHP (for all I know, it's not even possible). What you do is to simply open a URL the same way you open a file. For example:

Code: Select all

 
 
// Open a URL. This is equivalent to opening this page in a browser. 
// If you want to send a variable and its value to the recieving script, use GET values as exemplified below.
$url=fopen("http://www.yourwebsite.com?a_variable=a_value", 'r');
 
// If relevant in your case, read the page into a string:
$pageContent=stream_get_contents($url);
 
// Close connection
fclose($url);
 
 

Re: XMLHttpRequest in php help

Posted: Sun Aug 03, 2008 12:25 pm
by califdon
XMLHttpRequest is a Javascript object, so it is unknown to PHP. And since it is a client-side technology, it couldn't be used in a server-side script anyway.

You might try to explain what it is that you want to do, then we might be able to guide you.

Re: XMLHttpRequest in php help

Posted: Sun Aug 03, 2008 3:22 pm
by yuri1992
i need to send form my server a 2 var to some adress , in POST METHOD

but i need to send from the server only

Re: XMLHttpRequest in php help

Posted: Sun Aug 03, 2008 3:44 pm
by Alan01252
Hmmm

I think what you are trying to do is sent post variables using your php script. In which case use a third party library like cURL


..Try this link

http://davidwalsh.name/execute-http-post-php-curl

If this is not what you were looking for I apologies, at least I tried ;)

Re: XMLHttpRequest in php help

Posted: Sun Aug 03, 2008 4:14 pm
by yuri1992
i sorry that my english so suck.
i try to explain agein'
i work with compony the do SMS servies.
i need to sent to domain.com/sms.asp 2 varblie in POST
mobile
msg
in this adress they check if my ip is the ip of my server and if its true
the make the SMS and send to the moblie that i sent him with the msg i sent him

the said me to use in WEBservice XMLHttpRequest
but i get that i cant use is in php .

Re: XMLHttpRequest in php help

Posted: Sun Aug 03, 2008 6:25 pm
by califdon
Don't worry about language, I am sure that I cannot write your language. :)

I think the previous responder is probably correct, you may need to use cURL, which must be supported in your PHP installation. Read these references. I am sorry I can't help you because I have never used cURL, but some others may be able to help you.

http://www.alt-php-faq.org/local/55/
http://us2.php.net/manual/en/book.curl.php
http://blog.mypapit.net/2006/02/sending ... -curl.html
http://www.askapache.com/htaccess/sendi ... -curl.html

Re: XMLHttpRequest in php help

Posted: Sun Aug 03, 2008 8:43 pm
by omniuni
I am still a bit confused, I think the problem is that you're trying one of ASP's strange methods of sending data. XMLHttpRequest is a javascript function. If you want to use it, you must first declare your XMLHttpRequest objects, and set some event to use it. This works only client-side. Javascript works very well with PHP, although to be honest, I've only had a few hours to really play with AJAX stuff.

I did find this page, which might help you out: http://us2.php.net/variables.external

Maybe you can give us a link or an example that will better explain what you want to do?

Also, it might help to tell us what ASP language you're coming from. To be honest, I can't quite tell what that ASP code is supposed to DO.

Edit: after looking at that code a bit more, maybe this will help? http://netevil.org/blog/2006/nov/http-p ... thout-curl

Re: XMLHttpRequest in php help

Posted: Tue Aug 05, 2008 9:27 am
by yuri1992
tanks to all....