Raised This Month: $ Target: $400
 0% 

Sockets -> PHP script problem


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-19-2009 , 15:43   Sockets -> PHP script problem
Reply With Quote #1

I have this simple plugin to test how to use POST in sockets.
Code:
#include < amxmodx > #include < amxmisc > #include < sockets > new const HOSTNAME[ ] = "exolent.zinkhosting.net"; new const SCRIPT[ ] = "plugin_upload.php"; const PORT = 80; public plugin_init( ) {     register_plugin( "Socket -> PHP Test", "0.0.1", "Exolent" ); } public client_authorized( client ) {     static szName[ 32 ], szAuthid[ 35 ], szIP[ 32 ];     get_user_name( client, szName, 31 );     get_user_authid( client, szAuthid, 34 );     get_user_ip( client, szIP, 31, 1 );         // 1 char = 3 hex places ( %XX )     // ( ( 32 - 1 ) * 3 ) + 1 = 94     // ( ( 35 - 1 ) * 3 ) + 1 = 103     static szFixedName[ 94 ], szFixedAuthid[ 103 ], szFixedIP[ 94 ];     FormatString( szName, szFixedName, 93 );     FormatString( szAuthid, szFixedAuthid, 102 );     FormatString( szIP, szFixedIP, 93 );         log_amx( "Sending data: ^"%s^" ^"%s^" ^"%s^"", szFixedName, szFixedAuthid, szFixedIP );         static szSocketQuery[ 512 ], iDefaultLen;     if( !iDefaultLen )     {         iDefaultLen = formatex( szSocketQuery, 511, "POST /%s HTTP/1.1^r^nHost: %s^r^n^r^n", SCRIPT, HOSTNAME );     }     formatex( szSocketQuery[ iDefaultLen ], 511 - iDefaultLen,\         "name=%s&steamid=%s&ip=%s",\         szFixedName,\         szFixedAuthid,\         szFixedIP         );         new iError, hSocket = socket_open( HOSTNAME, PORT, SOCKET_TCP, iError );     if( hSocket > 0 && !iError )     {         socket_send( hSocket, szSocketQuery, strlen( szSocketQuery ) );                 socket_close( hSocket );     }     else     {         log_amx( "There was an error when creating the socket to %s:%i", HOSTNAME, PORT );                 switch( iError )         {             case 1:             {                 log_amx( "Error when creating socket." );             }             case 2:             {                 log_amx( "Couldn't resolve the hostname." );             }             case 3:             {                 log_amx( "Couldn't connect to given hostname:port." );             }         }     } } stock FormatString( const szInput[ ], szOutput[ ], iLen ) {     static const HEXCHARS[ 16 ] = {         '0', '1', '2', '3', '4', '5', '6', '7',         '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'     };         new iPos, cChar, iFLen;     while( ( cChar = szInput[ iPos ] ) && iFLen < iLen )     {         if( cChar == 0x20 ) // 0x20 = space character         {             szOutput[ iFLen++ ] = '+';         }         else if( !( 'A' <= cChar <= 'Z' )         && !( 'a' <= cChar <= 'z' )         && !( '0' <= cChar <= '9' ) )         {             if( ( iFLen + 3 ) > iLen )             {                 break;             }             else if( cChar > 0xFF )             {                 cChar = '*';             }                         szOutput[ iFLen++ ] = '%';                         if( cChar < 16 )             {                 szOutput[ iFLen++ ] = HEXCHARS[ 0 ];             }                         while( cChar > 0 )             {                 szOutput[ iFLen++ ] = HEXCHARS[ cChar % 16 ];                 cChar /= 16;             }         }         else         {             szOutput[ iFLen++ ] = cChar;         }                 iPos++;     } }

Name: "wtk. Exolent[jNr]"
SteamID: "STEAM_0:1:2058929"
IP: "##.##.##.##" (get away from my IP )

Log Results:
Code:
L 10/19/2009 - 12:27:44: [upload_test.amxx] Sending data: "wtk%E2+Exolent%B5jNr%D5" "STEAM%F50%A31%A32058929" "##%E2##%E2##%E2##"
Here is the PHP script that handles the information:
PHP Code:
<?php

$name 
trim$_POST"name" ] );
$steamid trim$_POST"steamid" ] );
$ip trim$_POST"ip" ] );

$filename "httptest.txt";

$file_handle fopen$filename"a+" );
fputs$file_handle"\"" $name "\" \"" $steamid "\" \"" $ip "\"\n" );
fclose$file_handle );

?>
The problem is in the results of the file that saves the information that was sent:
Code:
"" "" ""
"" "" ""
"" "" ""
"" "" ""
The log messages from the plugin show that the plugin's part in getting the information and preparing the socket and sending data is correct.
But the problem must be within the data being sent through the socket.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
 



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 17:40.


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