XMLHttpRequest in php help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yuri1992
Forum Newbie
Posts: 10
Joined: Sun Aug 03, 2008 8:49 am

XMLHttpRequest in php help

Post 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 ?
pkbruker
Forum Commoner
Posts: 32
Joined: Sun Aug 03, 2008 9:36 am
Location: Oslo, Norway

Re: XMLHttpRequest in php help

Post 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);
 
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: XMLHttpRequest in php help

Post 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.
yuri1992
Forum Newbie
Posts: 10
Joined: Sun Aug 03, 2008 8:49 am

Re: XMLHttpRequest in php help

Post 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
Alan01252
Forum Newbie
Posts: 12
Joined: Sun Aug 03, 2008 3:20 pm

Re: XMLHttpRequest in php help

Post 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 ;)
yuri1992
Forum Newbie
Posts: 10
Joined: Sun Aug 03, 2008 8:49 am

Re: XMLHttpRequest in php help

Post 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 .
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: XMLHttpRequest in php help

Post 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
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: XMLHttpRequest in php help

Post 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
yuri1992
Forum Newbie
Posts: 10
Joined: Sun Aug 03, 2008 8:49 am

Re: XMLHttpRequest in php help

Post by yuri1992 »

tanks to all....
Post Reply