aRo` automating your e-commerce

This blog has been neglected due to the success of Solidshops.com
18Aug/07

capture the loading time of your php pages

If you want to add a feature to your website that shows the loading time of the page just impliment the code below.

Offcourse php is a serverside language so the result is the time needed to generate the html on the server. This does not include sending the page back to the browsers who has to render it. But it's quite accurate.

PHP:
  1. // in the beginning of the page
  2. $start_time = explode(' ', microtime());
  3. $start_time = $start_time[1] + $start_time[0];
  4.  
  5. // at the end of the page
  6. $end_time = explode(' ', microtime());
  7. $total_time = $end_time[0] + $end_time[1] - $start_time;
  8. printf('Page loaded in  %.3f seconds.', $total_time);

Popularity: 2% [?]

Filed under: php No Comments
10Aug/07

writing the recursive path for all items that contain data in XML file

This little php functions shows how to write the recursive XMLpath for all nodes that contain values.

XML:
  1. $xmlstr = <<<XML
  2. <?xml version='1.0' standalone='yes'?>
  3. <movies>
  4.  <movie>
  5.   <title>PHP: Behind the Parser</title>
  6.   <characters>
  7.    <character>
  8.     <name>Ms. Coder</name>
  9.     <actor>Onlivia Actora</actor>
  10.    </character>
  11.    <character>
  12.     <name>Mr. Coder</name>
  13.     <actor>El Act&#211;r</actor>
  14.    </character>
  15.   </characters>
  16.   <plot>
  17.    So, this language. It's like, a programming language. Or is it a
  18.    scripting language? All is revealed in this thrilling horror spoof
  19.    of a documentary.
  20.   </plot>
  21.   <rating type="thumbs">7</rating>
  22.   <rating type="stars">5</rating>
  23.  </movie>
  24. </movies>
  25. XML;

PHP:
  1. $xml = new SimpleXMLElement($xmlstr);
  2. //SimpleXML_recursive($xml-&gt;xpath('//movie/characters/character'));
  3. SimpleXML_recursive($xml);function SimpleXML_recursive($xml,$parent="")
  4. {
  5. $child_count = 0;
  6. foreach($xml as $key=&gt;$value)
  7. {
  8. $child_count++;
  9. if(SimpleXML_recursive($value,$parent."/".$key) == 0)  // no childern
  10. {
  11. if($value-&gt;attributes() &lt;&gt; ""){
  12. $att = "[@".$value-&gt;attributes()."]";
  13. }
  14. print($parent . "/" . (string)$key .$att. "
  15. \n");
  16. }
  17. }
  18. return $child_count;
  19. }

This is the result:

/movie/title
/movie/characters/character/name
/movie/characters/character/actor
/movie/characters/character/name
/movie/characters/character/actor
/movie/plot
/movie/rating[@thumbs]
/movie/rating[@stars]

Now you can use this code to map the XML fields against the database fields.

Popularity: 2% [?]

Filed under: php, xml No Comments
8Aug/07

sending a mail with asp on win2k3

While migrating an application from an old IIS4(NT) server to a new win2003 machine there were some errors with emails.

It's always better to use a default component over a 3th party tool. That's why you should use CDO.

CDO (Collaboration Data Objects) is a Microsoft technology that is designed to simplify the creation of messaging applications.

However there are 2 versions of CDO: CDOSYS and CDONT.

Microsoft doesn't support CDONTs anymore on win2k/XP and 2k3.

So the only thing i had to change to make it work, was to change te version.

The code below works on windows 2003.

ASP:
  1. &lt;%
  2. Set myMail=CreateObject("CDO.Message")
  3.  
  4. myMail.Subject="test"
  5. myMail.From="name@domain.com"
  6. myMail.To="name@domain.com"
  7. myMail.TextBody="test"
  8.  
  9. myMail.Configuration.Fields.Item _
  10. ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
  11. 'Name or IP of remote SMTP server
  12. myMail.Configuration.Fields.Item _
  13. ("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
  14. ="relay1.smtp.local"
  15. 'Server port
  16. myMail.Configuration.Fields.Item _
  17. ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
  18. =25
  19. myMail.Configuration.Fields.Update
  20.  
  21. myMail.Send
  22.  
  23. set myMail=nothing
  24. response.write "mail send succesfully"

Popularity: 3% [?]

Filed under: asp No Comments