We all know that PHP is an HTML embedded language, PHP and Microsoft's ASP quite a bit similar, is a server-side implementation of embedded HTML document scripting language, language style has similar to C language, is now widely used by many web site programmers. This article describes in detail the PHP recursive array. The PHP program needs to write the received data to the "official database running on line" and "Test Database for development debugging".
and the test database may often face the table structure, fields, configuration information to make adjustments and so on, very unstable, the probability of error is very high, if using a.php program at the same time write "official database" and "Test Database", will inevitably affect the online operation of the official services. So, I thought of using the PHP Curl Extension library to pass the generated $data array post to the PHP program, and then the PHP program continues to execute the code that writes the "official database." PHP program to pass the $data array to the PHP program is done, as for how PHP processing, it is not the case of PHP, PHP program even if the "test database" failure, will not affect the PHP program.
PHP recursive array source code:
- php
- $data ["username"]= "Zhang Feast";
- $data ["Password"]= "do not know";
- $data ["IP"]= "192.168.0.18";
- Register_shutdown_function ("Post_data", $data);
- function Post_data ($data)
- //{
- $ Curl = New Curl_class ();
- $ Post = @ $curl- > post ("http://127.0.0.1/b.php", $data);//This is b.php's access address, please modify it yourself
- //}
- Curl Class
- Class Curl_class
- {
- function Curl_class ()
- {
- return true;
- }
- function Execute ($method, $url, $ fields = ', $useragent = /c8>', $httpheaders = ', $username = '' , $ Password = '' )
- {
- $ CH = Curl_class :: Create ();
- if (false = = = $ch)
- {
- return false;
- }
- if (is_string ($url) && strlen ($url))
- {
- $ ret = curl_setopt ($ch, Curlopt_url, $url);
- }
- Else
- {
- return false;
- }
- Whether to display header information
- curl_setopt ($ch, Curlopt_header, false);
- //
- curl_setopt ($ch, Curlopt_returntransfer, true);
- if ($username! = ")
- {
- curl_setopt ($ch, Curlopt_userpwd, $username. ':' . $password);
- }
- $ Method = Strtolower ($method);
- if (' post ' = = $method)
- {
- curl_setopt ($ch, Curlopt_post, true);
- if (Is_array ($fields))
- {
- $ sets = Array ();
- foreach ($fields as $key => $val)
- {
- $sets [] = $key. '=' . UrlEncode ($val);
- }
- $ Fields = implode (' & ', $sets);
- }
- curl_setopt ($ch, Curlopt_postfields, $fields);
- }
- else if (' put ' = = $method)
- {
- curl_setopt ($ch, Curlopt_put, true);
- }
- curl_setopt ($ch, curlopt_progress, true);
- curl_setopt ($ch, Curlopt_verbose, true);
- curl_setopt ($ch, Curlopt_mute, false);
- curl_setopt ($ch, Curlopt_timeout, 3);//sets the curl timeout in seconds, for example, post the message 3 seconds after the automatic end of the run.
- if (strlen ($userAgent))
- {
- curl_setopt ($ch, curlopt_useragent, $userAgent);
- }
- if (Is_array ($httpHeaders))
- {
- curl_setopt ($ch, Curlopt_httpheader, $httpHeaders);
- }
- $ ret = curl_exec ($ch);
- if (Curl_errno ($ch))
- {
- Curl_close ($ch);
- Return Array (Curl_error ($ch), Curl_errno ($ch));
- }
- Else
- {
- Curl_close ($ch);
- if (!is_string ($ret) | |!strlen ($RET))
- {
- return false;
- }
- return $ret;
- }
- }
- function Post ($url, $fields, $useragent = ", $httpheaders = '' , $ username = '' , $ Password = '' )
- {
- $ ret = Curl_class :: Execute (' POST ', $url, $fields, $userAgent, $httpHeaders, $username, $password);
- if (false = = = $ret)
- {
- return false;
- }
- if (Is_array ($ret))
- {
- return false;
- }
- return $ret;
- }
- function Get ($url, $useragent = ", $httpheaders = '' , $ username = '' , $ Password = '' )
- {
- $ ret = Curl_class :: Execute (' GET ', $url, ', $userAgent, $httpHeaders, $username, $password);
- if (false = = = $ret)
- {
- return false;
- }
- if (Is_array ($ret))
- {
- return false;
- }
- return $ret;
- }
- function Create ()
- {
- $ CH = NULL ;
- if (!function_exists (' Curl_init '))
- {
- return false;
- }
- $ CH = Curl_init ();
- if (!is_resource ($ch))
- {
- return false;
- }
- return $ch;
- }
- }
- ?>
PHP Recursive Array Code:
- Php
- Ignore_user_abort ()///After the connection is interrupted (for example, to close the browser) continue to execute the following script until processing is complete.
- Set_time_limit (0);
- $ Get_data = file_get_contents ("Php://input");
- $ Explode Explodedata = Explode ("&", $get _data);
- foreach ($explodedata as $key => $value)//restore array
- {
- List ($realkey, $realvalue) = explode ("=", $value);
- $data [UrlDecode ($realkey)] = UrlDecode ($realvalue);
- }
- Now that the $data array is the same as in the a.php, you can then manipulate the $data array to suit your needs.
- //......
- ?>
http://www.bkjia.com/PHPjc/446465.html www.bkjia.com true http://www.bkjia.com/PHPjc/446465.html techarticle we all know that PHP is an HTML embedded language, PHP and Microsoft's ASP quite a bit similar, is a server-side implementation of embedded HTML document scripting language, language style ...