Raised This Month: $ Target: $400
 0% 

sending data to php script


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 07-17-2007 , 13:31   sending data to php script
Reply With Quote #1

How do you send data to a script and get the results?

This is how it was done from a brower from another php script:
PHP Code:
$sendMsg = new sendMsg($_POST["message"]);
$sendMsg->send()
 
// returns the result
$sendMsg->result 
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.

Last edited by Cheap_Suit; 07-17-2007 at 21:12.
Cheap_Suit is offline
hackziner
Senior Member
Join Date: Sep 2006
Location: France
Old 07-18-2007 , 12:38   Re: sending data to php script
Reply With Quote #2

Hum, so you want send data from a amxmodx plugin to a php script or send data from a php script to a amxmodx plugin ? who open the connexion ? In fact I think you've no choice because the socket module doesn't allow to listen for tcp connection ( I'm not sure @ 100% ).

edit : I've read your pm too fast ... ...


There is to method to send datas to a php script, get and post ... but get is easier


First we've to know how do a post/get request ...

The best way to understand is to analyse a post request.
//Open wireshark, which is certainly the best packet sniffer
//Open a thread
//Write a reply
//Record packet & click on reply

We get in the first packet
PHP Code:
POST http://forums.alliedmods.net/newreply.php?do=postreply&t=58056 HTTP/1.1
Hostforums.alliedmods.net
User
-AgentMozilla/5.0 (WindowsUWindows NT 5.1frrv:1.8.1.4Gecko/20070515 Firefox/2.0.0.4
Accept
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*;q=0.5
Accept
-Languagefr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept
-Encodinggzip,deflate
Accept
-CharsetISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep
-Alive300
Proxy
-Connectionkeep-alive
Content
-Typeapplication/x-www-form-urlencoded
Referer
http://forums.alliedmods.net/showthread.php?t=58056
Content-Length215
Pragma
no-cache
Cache
-Controlno-cache 
ofc there is a \r\n at the end of each line and a double at the end of the first packet

in the second packet
PHP Code:
ajax=1&ajax_lastpost=1184769975&message=Just%20useless%2C%20but%20well%20coded%20%3A%29%3Cbr%3E&wysiwyg=1&styleid=0&signature=1&fromquickreply=1&s=&do=postreply&t=58056&p=who%20cares&parseurl=1&loggedinuser=21173&s
So, most of the thing here are useless for us.


so to do a get request you've just to send:
PHP Code:
hackziner@hackziner:/usr/lib/cgi-bin/server/pr_directurltelnet amxmodx.org 80
Trying 74.52.23.194
...
Connected to c2.17.344a.static.theplanet.com.
Escape character is '^]'.
get http://forums.alliedmods.net/showthread.php?t=58038\r\n 
t take the value 58038 ... to get this value in php "$t = _GET["t"];"

If you wanna try, just open telnet and do the same thing ...

after sending this request, the http server reply on the same connexion.
So you can see if your request works with telnet ...


The second one with the post ... I'm too lazy It's the same thing but datas are after the http header ( here in the second packet )


So, how do to this thing in pawn ... just copy an other code


Admin mail do the same thing.

#include <sockets>

new buff[1024]
new socket = socket_open( "http://www.amxmodx.org"", 80, SOCKET_TCP, error );

//http uses tcp and the default port is 80 ...
formatex( buff, 1023, "get http://forums.alliedmods.net/showthread.php?t=58038^r^n" );

socket_send( socket, buff, 1024);


set a task with
if (socket_change( socket) socket_recv( socket, buff, 1023)
to get the reply...

The reply is something like that :



PHP Code:
HTTP/1.0 200 OK
Date: Wed, 18 Jul 2007 16:11:07 GMT
Server: Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.7a DAV/2
X-Powered-By: PHP/5.2.2
Cache-Control: private
Pragma: private
Content-Type: text/xml; charset=windows-1252
X-Cache: MISS from proxy.free.fr
X-Cache-Lookup: MISS from proxy.free.fr:3128
Proxy-Connection: close

<?xml version="1.0" encoding="windows-1252"?>
<postbits>
<postbit postid="504914"><![CDATA[<!-- post #504914 -->

<!-- open content container -->
Some servers need a full and correct request, other only need something which looks like the normal request
__________________

Last edited by hackziner; 07-19-2007 at 02:15. Reason: deleted something
hackziner is offline
Send a message via ICQ to hackziner Send a message via AIM to hackziner Send a message via MSN to hackziner Send a message via Yahoo to hackziner Send a message via Skype™ to hackziner
Rolnaaba
Veteran Member
Join Date: May 2006
Old 07-18-2007 , 12:38   Re: sending data to php script
Reply With Quote #3

Quote:
Originally Posted by Cheap_Suit View Post
How do you send data to a script and get the results?
he wants both. Send a mesage and get what it sends back.
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 07-18-2007 , 13:00   Re: sending data to php script
Reply With Quote #4

You need to use sockets to do this.

Here's a tut by Darksnow
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 07-18-2007 , 13:22   Re: sending data to php script
Reply With Quote #5

I've seen that and still have no idea what to put in socket_send.

Edit: The php script return's a number regarding if the message was sent successfully
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.

Last edited by Cheap_Suit; 07-18-2007 at 13:26.
Cheap_Suit is offline
hackziner
Senior Member
Join Date: Sep 2006
Location: France
Old 07-18-2007 , 13:24   Re: sending data to php script
Reply With Quote #6

Lol, I'll sum up my previous post

GET request is easier than POST

You have to open a TCP connection to the host

new socket = socket_open( "http://www.amxmodx.org"", 80, SOCKET_TCP, error );

You have to format a GET request

formatex( buff, 1023, "get http://forums.alliedmods.net/showthread.php?t=58038^r^n" );

t is a variable and 58038 the value of t

send the request

socket_send( socket, buff, 1024);

define a task to get the page

if (socket_change( socket) //check if there is something waiting in the socket
socket_recv( socket, buff, 1023) //put the socket in buff


If you wanna try if you php page works, just open telnet, type the request and see the result ...
__________________

Last edited by hackziner; 07-18-2007 at 13:28.
hackziner is offline
Send a message via ICQ to hackziner Send a message via AIM to hackziner Send a message via MSN to hackziner Send a message via Yahoo to hackziner Send a message via Skype™ to hackziner
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 07-18-2007 , 21:16   Re: sending data to php script
Reply With Quote #7

Quote:
Originally Posted by hackziner View Post
Lol, I'll sum up my previous post

GET request is easier than POST

You have to open a TCP connection to the host

new socket = socket_open( "http://www.amxmodx.org"", 80, SOCKET_TCP, error );

You have to format a GET request

formatex( buff, 1023, "get http://forums.alliedmods.net/showthread.php?t=58038^r^n" );

t is a variable and 58038 the value of t

send the request

socket_send( socket, buff, 1024);

define a task to get the page

if (socket_change( socket) //check if there is something waiting in the socket
socket_recv( socket, buff, 1023) //put the socket in buff


If you wanna try if you php page works, just open telnet, type the request and see the result ...
I understand little to none about sockets and php and this helped alot. But I was thinking to send it
to the main php script. How would I send the message using sockets like the code in my first post.

This is where I want to send my message and get the result from $result.
PHP Code:
class sendMsg
{
 var 
$_msg;
 var 
$result;
 
 function 
sendMsg($message)
 {
  
$this->_msg $message;
 } 
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 07-18-2007 , 13:32   Re: sending data to php script
Reply With Quote #8

Thanks, I'll see if I can get to work later.
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode