[Solved] PHP returning a request POST. 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
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

[Solved] PHP returning a request POST. HELP!

Post by myleow »

Taking into consideration that i am using PHP 4.1.2 (Debian Stable version) to build the SyncML server.

==========================================
==Below is the Header information
==from $_SERVER received by server
==========================================

CONTENT_LENGTH == 1340
CONTENT_TYPE == application/vnd.syncml+wbxml
DOCUMENT_ROOT == /var/www
HTTP_ACCEPT == application/vnd.syncml+wbxml, text/x-vcard, text/x-vcalendar, image/vnd.wap.wbmp, image/gif
HTTP_ACCEPT_APPLICATION == 1,2
HTTP_ACCEPT_CHARSET == US-ASCII, ISO-8859-1, UTF-8, ISO-10646-UCS-2
HTTP_ACCEPT_LANGUAGE == en
HTTP_BEARER_INDICATION == 0
HTTP_CLIENT_IP == 10.184.24.197
HTTP_HNAME1 == hvalue1
HTTP_HNAME2 ==
HTTP_HNAME3 == hvalue3
HTTP_HOST == pc6.homelinux.com
HTTP_USER_AGENT == SonyEricssonT616/R101 Profile/MIDP-1.0 Configuration/CLDC-1.0
HTTP_VIA == WTP/1.1 proatlwap02 (Nokia WAP Gateway 4.0/ECD10/4.0.64), HTTP/1.1 proatledmpxy02[0540000D] (Traffic-Server/5.1.3-55590 [uScM])
HTTP_X_NETWORK_INFO == GPRS,unsecured
HTTP_X_NOKIA_BEARER == GPRS
HTTP_X_NOKIA_CONNECTION_MODE == CMODE
HTTP_X_NOKIA_GATEWAY_ID == NWG/4.0/Build64
HTTP_X_WAP_PROFILE == http://wap.sonyericsson.com/UAprof/T616R101.xml
PATH == /bin:/usr/bin:/sbin:/usr/sbin
REMOTE_ADDR == 66.94.27.3
REMOTE_PORT == 35374
========================================

What i did to reply to this request from my server after processing the SyncML packages. I wrote

Code: Select all

<?php

header("POST HTTP/1.1 200 OK");
header("Content-Type: application/vnd.syncml+wbxml");
header("Accept-Charset: UTF-8");
header("transfer-coding: chunked");

echo $wbxml_obj //this is the response encoded in WBXML
?>
Is this how i am suppose to send it back to the client?

Is there a way to dump the header that i sent out so i can check it?

Please HELP!!!

Thank you in advance

Regards
Mian
Last edited by myleow on Thu Aug 12, 2004 10:28 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

from what I remember, PHP4 doesn't have a function to get the headers that'd be sent. You can write a test to see the headers though using [php_man]curl[/php_man]: viewtopic.php?t=24724&highlight=curl&start=5


your previous post on this, was accidently attached to an entirely different thread, and was split and moved to the linux forum...
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Hope this helps clarifies the problem.

Post by myleow »

Below is the message i posted on a SyncML group on yahoo.com, but i suspect that it is not the problem with SyncML protocol and how it is handled. I am suspecting that my PHP Script is not sending the package back out, either incorrect headers or not going to the right address.

Anything regards PHP, i think would be best to ask on this forum. I was asking for a way to look at my sent out header is because i am thinking that that might be causing problem.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Taking into consideration that i am using PHP 4.1.2
(Debian Stable version) to build the SyncML server.

I received the Client Initial Package as shown below

Code: Select all

&lt;SyncML&gt;
&lt;SyncHdr&gt;
&lt;VerDTD&gt;1.0&lt;/VerDTD&gt;
&lt;VerProto&gt;SyncML/1.0&lt;/VerProto&gt;
&lt;SessionID&gt;11&lt;/SessionID&gt;
&lt;MsgID&gt;1&lt;/MsgID&gt;

&lt;Target&gt;&lt;LocURI&gt;http://pc6.homelinux.com/~myleow/syncml/index.php&lt;/LocURI&gt;&lt;/Targ\
et&gt;
&lt;Source&gt;&lt;LocURI&gt;010197000074551&lt;/LocURI&gt;&lt;/Source&gt;
&lt;Meta&gt;&lt;MaxMsgSize
xmlns='syncml:metinf'&gt;2700&lt;/MaxMsgSize&gt;&lt;/Meta&gt;
&lt;/SyncHdr&gt;

&lt;SyncBody&gt;
&lt;Put&gt;
&lt;CmdID&gt;1&lt;/CmdID&gt;
&lt;Meta&gt;&lt;Type
xmlns='syncml:metinf'&gt;application/vnd.syncml-devinf+wbxml&lt;/Type&gt;&lt;/Meta&gt;
&lt;Item&gt;
&lt;Source&gt;&lt;LocURI&gt;./devinf10&lt;/LocURI&gt;&lt;/Source&gt;
&lt;Data&gt;&lt;DevInf&gt;...&lt;/DevInf&gt;&lt;/Data&gt;
&lt;/Item&gt;
&lt;/Put&gt;

&lt;Alert&gt;
&lt;CmdID&gt;2&lt;/CmdID&gt;
&lt;Cred&gt;
&lt;Meta&gt;
&lt;Format xmlns='syncml:metinf'&gt;b64&lt;/Format&gt;
&lt;Type
xmlns='syncml:metinf'&gt;syncml:auth-basic&lt;/Type&gt;
&lt;/Meta&gt;
&lt;Data&gt;YWRnam06ZG13YWp0Lmdw&lt;/Data&gt;
&lt;/Cred&gt;
&lt;Data&gt;201&lt;/Data&gt;
&lt;Item&gt;
&lt;Target&gt;&lt;LocURI&gt;Contacts&lt;/LocURI&gt;&lt;/Target&gt;
&lt;Source&gt;&lt;LocURI&gt;EriPBDB&lt;/LocURI&gt;&lt;/Source&gt;
&lt;Meta&gt;
&lt;Anchor xmlns='syncml:metinf'&gt;
&lt;Last xmlns='syncml:metinf'&gt;41&lt;/Last&gt;
&lt;Next xmlns='syncml:metinf'&gt;41&lt;/Next&gt;
&lt;/Anchor&gt;
&lt;/Meta&gt;
&lt;/Item&gt;
&lt;/Alert&gt;
&lt;Final/&gt;
&lt;/SyncBody&gt;
&lt;/SyncML&gt;
============================================
====The Following is my response package====
============================================

Code: Select all

&lt;SyncML&gt;
&lt;SyncHdr&gt;
&lt;VerDTD&gt;1.0&lt;/VerDTD&gt;
&lt;VerProto&gt;SyncML/1.0&lt;/VerProto&gt;
&lt;SessionID&gt;11&lt;/SessionID&gt;
&lt;MsgID&gt;1&lt;/MsgID&gt;
&lt;Target&gt;&lt;LocURI&gt;010197000074551&lt;/LocURI&gt;&lt;/Target&gt;

&lt;Source&gt;&lt;LocURI&gt;http://pc6.homelinux.com/~myleow/syncml/index.php&lt;/LocURI&gt;&lt;/Sour\
ce&gt;
&lt;Meta&gt;&lt;MaxMsgSize
xmlns='syncml:metinf'&gt;2700&lt;/MaxMsgSize&gt;&lt;/Meta&gt;
&lt;/SyncHdr&gt;

&lt;SyncBody&gt;
&lt;Status&gt;
&lt;CmdID&gt;1&lt;/CmdID&gt;
&lt;MsgRef&gt;1&lt;/MsgRef&gt;
&lt;CmdRef&gt;0&lt;/CmdRef&gt;
&lt;Cmd&gt;SyncHdr&lt;/Cmd&gt;

&lt;TargetRef&gt;http://pc6.homelinux.com/~myleow/syncml/index.php&lt;/TargetRef&gt;
&lt;SourceRef&gt;010197000074551&lt;/SourceRef&gt;
&lt;Chal&gt;
&lt;Meta&gt;
&lt;Type
xmlns='syncml:metinf'&gt;syncml:auth-basic&lt;/Type&gt;
&lt;Format xmlns='syncml:metinf'&gt;b64&lt;/Format&gt;
&lt;/Meta&gt;
&lt;/Chal&gt;
&lt;Data&gt;407&lt;/Data&gt;
&lt;/Status&gt;

&lt;Status&gt;
&lt;CmdID&gt;2&lt;/CmdID&gt;
&lt;MsgRef&gt;1&lt;/MsgRef&gt;
&lt;CmdRef&gt;1&lt;/CmdRef&gt;
&lt;Cmd&gt;Put&lt;/Cmd&gt;
&lt;Data&gt;407&lt;/Data&gt;
&lt;/Status&gt;

&lt;Status&gt;
&lt;CmdID&gt;3&lt;/CmdID&gt;
&lt;MsgRef&gt;1&lt;/MsgRef&gt;
&lt;CmdRef&gt;2&lt;/CmdRef&gt;
&lt;Cmd&gt;Alert&lt;/Cmd&gt;
&lt;Data&gt;407&lt;/Data&gt;
&lt;/Status&gt;
&lt;Final/&gt;
&lt;/SyncBody&gt;
&lt;/SyncML&gt;
The reponse package is in turn encoded using my WBXML
Codec. I think my codec is working fine because when
i encode the decoded client initial message, it is
exactly the same.

Anyway. After i encoded the reply, i called it
$wbxml_obj in my PHP script.

I then proceed in sending it back out by

Code: Select all

<?php
header ("POST HTTP/1.1 200 OK");
header ("Content-Type: application/vnd.syncml+wbxml");
header ("Accept-Charset: UTF-8");
header ("transfer-coding: chunked");
echo $wbxml_obj;
?>
I am stuck after this stage, because there is no
indication of error beside Synchronization Interrupted
on my Sony Ericsson T-616/610.

I don't know if the package is actually sent out from
my server, if the client received the package or if
the package itself has error. Basically, i can't even
start the communication channel going with a simple
challenge.

==========================================
==Below is the Header information
==from $_SERVER received by server
==========================================

Code: Select all

CONTENT_LENGTH == 1340
CONTENT_TYPE == application/vnd.syncml+wbxml
DOCUMENT_ROOT == /var/www
HTTP_ACCEPT == application/vnd.syncml+wbxml,
text/x-vcard, text/x-vcalendar, image/vnd.wap.wbmp,
image/gif
HTTP_ACCEPT_APPLICATION == 1,2
HTTP_ACCEPT_CHARSET == US-ASCII, ISO-8859-1, UTF-8,
ISO-10646-UCS-2
HTTP_ACCEPT_LANGUAGE == en
HTTP_BEARER_INDICATION == 0
HTTP_CLIENT_IP == 10.184.24.197
HTTP_HNAME1 == hvalue1
HTTP_HNAME2 ==
HTTP_HNAME3 == hvalue3
HTTP_HOST == pc6.homelinux.com
HTTP_USER_AGENT == SonyEricssonT616/R101
Profile/MIDP-1.0 Configuration/CLDC-1.0
HTTP_VIA == WTP/1.1 proatlwap02 (Nokia WAP Gateway
4.0/ECD10/4.0.64), HTTP/1.1 proatledmpxy02&#1111;0540000D]
(Traffic-Server/5.1.3-55590 &#1111;uScM])
HTTP_X_NETWORK_INFO == GPRS,unsecured
HTTP_X_NOKIA_BEARER == GPRS
HTTP_X_NOKIA_CONNECTION_MODE == CMODE
HTTP_X_NOKIA_GATEWAY_ID == NWG/4.0/Build64
HTTP_X_WAP_PROFILE ==
http://wap.sonyericsson.com/UAprof/T616R101.xml
PATH == /bin:/usr/bin:/sbin:/usr/sbin
REMOTE_ADDR == 66.94.27.3
REMOTE_PORT == 35374
SCRIPT_FILENAME == /home/myleow/public_html/syncml/index.php
SERVER_ADDR == 192.168.1.4
SERVER_ADMIN == webmaster@icees.com
SERVER_NAME == www.icees.com
SERVER_PORT == 80
SERVER_SIGNATURE == &lt;ADDRESS&gt;Apache/1.3.26 Server at www.icees.com Port 80&lt;/ADDRESS&gt;

SERVER_SOFTWARE == Apache/1.3.26 (Unix) Debian GNU/Linux PHP/4.1.2
UNIQUE_ID == QRv@Yn8AAAEAABlzAd0
GATEWAY_INTERFACE == CGI/1.1
SERVER_PROTOCOL == HTTP/1.1
REQUEST_METHOD == POST
QUERY_STRING ==
REQUEST_URI == /~myleow/syncml/index.php
SCRIPT_NAME == /~myleow/syncml/index.php
PATH_TRANSLATED == /home/myleow/public_html/syncml/index.php
PHP_SELF == /~myleow/syncml/index.php
argv == Array
argc == 0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Thank you in advance

Regards
Mian
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

since you didn't bother to read my post, or rather the post I linked to:

Code: Select all

HTTP/1.1 200 OK
Date: Fri, 13 Aug 2004 00:33:10 GMT
Server: Apache/1.3.26 (Unix) Debian GNU/Linux PHP/4.1.2
X-Powered-By: PHP/4.1.2
Content-Type: text/html; charset=iso-8859-1
is what is sent back for the headers when run through http...
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Index file

Post by myleow »

hehe :oops:

Thank you for posting it, i will see if that helps.

did you get that fromt the index.php from syncml directory?? If so why is it returning content-type to be text, instead of wbxml? Weird. What could be the problem?

Here is the index.php file.

Code: Select all

<?php
<?php
  include_once("wbxml2xml.php");
  include_once("sync_engine.php");
  include_once("xml_object.php");

  $fd2 = fopen("server.txt",'a');
  foreach ($_SERVER as $key => $value)
  {
    fputs($fd2, "$key == $value\n");
  }
  $fd2 = fclose($fd2);

  if(@$_SERVER["CONTENT_TYPE"] == "application/vnd.syncml+xml")
  {
    $fd = fopen("data.txt",'a');
    fputs($fd,$HTTP_RAW_POST_DATA);
    fputs($fd,"\n\n");
    $fd = fclose($fd);
  }
  elseif(@$_SERVER["CONTENT_TYPE"] == "application/vnd.syncml+wbxml")
  {
    $xml_string = '';

    //error checking
    $fd = fopen("temp.txt",'a');
    fputs($fd,$HTTP_RAW_POST_DATA);

    //change the raw data from http to xml string
    $xml_string = toxml($HTTP_RAW_POST_DATA);

    //error checking
    fputs($fd,"\n\n");
    $fd = fclose($fd);
    $fd1 = fopen("data.txt",'a');
    fputs($fd1,$xml_string);
    fputs($fd,"\n\n");
    $fd1 = fclose($fd1);

    //change the xml_string to xml object
    $request_xml_obj = create_xml_object($xml_string);

    //Create a session for this connection
    session_start();
    if(@$_SESSION["begin"] != 1)
    {
      //initial session variable for this session
      $_SESSION["username"] = '';
      $_SESSION["password"] = '';
      $_SESSION["authenticate"] = FALSE;
      $_SESSION["r_msg_id"] = 0;
      $_SESSION["session_id"] = 0;
      $_SESSION["msg_id"] = 1;
      $_SESSION["cmd_id"] = 0;
      $_SESSION["client"] = '';
      $_SESSION["server"] = '';

      $_SESSION["begin"] = 1;
    }
    }

    //create the response object
    $response_xml_obj = create_response($request_xml_obj);

    //convert the response_xml_obj back to wbxml
    $wbxml_obj = xml_object_to_wbxml($response_xml_obj);

    $content_length = strlen($wbxml_obj);

    //echo the header and the wbxml response to the client
    header ("POST HTTP/1.1 200 OK");
    header ("Content-Type: application/vnd.syncml+wbxml");
    header ("Accept-Charset: UTF-8");
    header("transfer-coding: chunked");

   //error checking
  $fd5 = fopen("server.txt",'a');
  fputs($fd5,"*****************************\n");
  $fd5 = fclose($fd5);

    echo $wbxml_obj;
  }
  else{}
  exit();
?>
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that header was kicked out of:

Code: Select all

http://pc6.homelinux.com/~myleow/syncml/index.php
using a browser agent string of:

Code: Select all

SonyEricssonT616/R101 Profile/MIDP-1.0 Configuration/CLDC-1.0
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Post by myleow »

It seems that it might be the header that is causing the problem.

I ran a small test

#1 Sleeping the server for 45 secs and not sending anything back.

The Sony Ericsson T-616 timed out on an average of 34 secs.

#2 instead of echo $wbxml_obj, i echo "This is junk". This result in Synchronization Interrupted in an average of 2 secs.

I then timed my echo $wbxml_obj, and the average is 4 secs. So PHP is sending out the package correctly. This eliminate my concern on PHP is not sending the package back.

Now the thing is either the Header is incorrect, or my package is malform.

But i am confuse as to why the header that you received were

Code: Select all

HTTP/1.1 200 OK 
Date: Fri, 13 Aug 2004 00:33:10 GMT 
Server: Apache/1.3.26 (Unix) Debian GNU/Linux PHP/4.1.2 
X-Powered-By: PHP/4.1.2 
Content-Type: text/html; charset=iso-8859-1
and not the header that i sent out, which is suppose to be

Code: Select all

HTTP/1.1 200 OK
Content-Type: application/vnd.syncml+wbxml; charset=UTF-8
Am i using the header() function wrongly to force the header that i want?

I really appreciate the help that you are providing.

Regards
Mian
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Post by myleow »

I wrote a client using Python to test out the stuff that was suppose to be sent to the phone and found out that there were warning in the message. So i used ob_start() to fix it.

It works now. Thank you for your help.

Regards
Mian
Post Reply