<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://blog.invenzzia.org/en/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Invenzzia... in English - Tag - visit</title>
  <link>http://blog.invenzzia.org/en/</link>
  <atom:link href="http://blog.invenzzia.org/en/feed/tag/visit/rss2" rel="self" type="application/rss+xml"/>
  <description></description>
  <language>en</language>
  <pubDate>Fri, 10 May 2013 13:58:34 +0100</pubDate>
  <copyright>Copyright &amp;copy; Invenzzia</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Open Power Classes: Visit information</title>
    <link>http://blog.invenzzia.org/en/post/Open-Power-Classes%3A-Visit-information</link>
    <guid isPermaLink="false">urn:md5:a7e3d3b815a05fc96c1833003e379160</guid>
    <pubDate>Sun, 28 Sep 2008 21:55:00 +0200</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Classes</category>
        <category>development</category><category>OPC</category><category>visit</category>    
    <description>&lt;p&gt;I'm currently working on a project written in Zend Framework and while trying to secure sessions, I noticed that this utility does not have any class that collects everything about the visitor and the request. The problem is quite serious, as many values in &lt;code&gt;$_SERVER&lt;/code&gt; depend on the installed server software, PHP mode (module, CGI, FastCGI...) and many other things. This means that the scripts should not rely on them without a proper processing, because it can even crash whole website after the software change (I experienced it not so long ago). Thankfully, I noticed that in the old OPF code, I have a class called &lt;code&gt;opfVisit&lt;/code&gt; that does this job. Now it's a part of the new Open Power Classes project :).&lt;/p&gt;    &lt;p&gt;Currently, the class &lt;code&gt;Opc_Visit&lt;/code&gt; provides the following information:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;IP address&lt;/li&gt;
&lt;li&gt;Host address&lt;/li&gt;
&lt;li&gt;Current request addresses, paths, file names, all server-independent, mod_rewrite-independent etc.&lt;/li&gt;
&lt;li&gt;Accepted browser languages, sorted by the priority.&lt;/li&gt;
&lt;li&gt;Cookie server and cookie path detection.&lt;/li&gt;
&lt;li&gt;Protocol and port detection.&lt;/li&gt;
&lt;li&gt;Browser detection (recognizes 26 browsers and search engines)&lt;/li&gt;
&lt;li&gt;Operating system detection (recognizes 10 Windows versions, 14 Linux distributions and 7 other Unix clones, including MacOS).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below, we can see a sample test script output called on my computer as &lt;code&gt;http://opl.libs.lh/trunk/dev/opc/test_visit.php/foo?bar=joe&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;
IP: 127.0.0.1
numericIP: 2130706433
host: localhost.localdomain
currentAddress: http://opl.libs.lh/trunk/dev/opc/test_visit.php/foo?bar=joe
currentFile: http://opl.libs.lh/trunk/dev/opc/test_visit.php
currentParams: /foo
currentPath: http://opl.libs.lh/trunk/dev/opc/
fileName: test_visit.php
pathInfo: /foo?bar=joe
protocol: http
port: 80
secure: false
languages: array ( 0 =&amp;gt; 'pl-PL', 1 =&amp;gt; 'pl', 2 =&amp;gt; 'en', )
browser: Opera 9.52
OS: Arch Linux 
cookieServer: opl.libs.lh
cookiePath: /trunk/dev/opc/
&lt;/pre&gt;


&lt;p&gt;The class API is more than simple:&lt;/p&gt;

&lt;pre&gt;php
&amp;lt;?php
	// OPL Initialization
	require('../../lib/opl/base.php');
	Opl_Loader::setDirectory('../../lib/');
	Opl_Registry::setState('opl_debug_console', true);
	spl_autoload_register(array('Opl_Loader', 'autoload'));
    
	try
	{
		$visit = Opc_Visit::getInstance();
    	
		$paramList = array(0 =&amp;gt;
			'IP', 'numericIP', 'host', 'currentAddress', 'currentFile', 'currentParams', 'currentPath', 'fileName',
			'pathInfo', 'protocol', 'port', 'secure', 'languages', 'browser', 'OS', 'cookieServer', 'cookiePath');
		
		echo '&amp;lt;ol&amp;gt;';
		foreach($paramList as $par)
		{
			$value = $visit-&amp;gt;$par;
			if(is_bool($value))
			{
				$value = ($value ? 'true' : 'false');
			}
	 		elseif(is_array($value))
			{
				$value = var_export($value, true);
			}
			echo '&amp;lt;li&amp;gt;'.$par.': &amp;lt;code&amp;gt;'.$value.'&amp;lt;/code&amp;gt;&amp;lt;/li&amp;gt;';
		}
		echo '&amp;lt;/ol&amp;gt;';
	}
	catch(Opl_Exception $e)
	{
		Opl_Error_Handler($e);
	}
?&amp;gt;
&lt;/pre&gt;


&lt;p&gt;We have here the singleton implementation and the magic &lt;code&gt;__get&lt;/code&gt; method used to generate and return the requested values.&lt;/p&gt;


&lt;p&gt;The class will be available in our SVN repository tomorrow or on Thursday, because I must clean up the code and add the recent inventions, such as Google Chrome or Windows Vista to the detectors.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/Open-Power-Classes%3A-Visit-information#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/Open-Power-Classes%3A-Visit-information#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/40</wfw:commentRss>
      </item>
    
</channel>
</rss>