Web services are taking over the world. I credit Twitter's epic rise to the availability of a simple but rich API. Why not use the same model for your own sites? Here's how to create a basic web service that provides an XML or JSON response using some PHP and MySQL. The PHP / MySQL copy /* require the user as the parameter */ if ( isset ( $_GET [ 'user' ] ) && intval ( $_GET [ 'user' ] ) ) { /* soak in the passed variable or set our own */ $number_of_posts = isset ( $_GET [ 'num' ] ) ? intval ( $_GET [ 'num' ] ) : 10 ; //10 is the default $format = strtolower ( $_GET [ 'format' ] ) == 'json' ? 'json' : 'xml' ; //xml is the default $user_id = intval ( $_GET [ 'user' ] ) ; //no default /* connect to the db */ $link = mysql_connect ( 'localhost' , 'username' , 'password' ) or die ( 'Cannot connect to the DB' ) ; mysql_select_db...
We can use either session_register or $_SESSION for registering session variable in php. Find below the difference between both of them. session_register () is a function and $_SESSION is a superglobal array . session_register() is used to register a session variable and it works only when register_globals is turned on . ( Turning ON register_globals will create mesh-ups, but some applications (e.g OScommerce) requires turning ON of register_globals) But $_SESSION works even when register_globals is turned off. If session_start() was not called before session_register() is called, an implicit call to session_start() with no parameters will be made. But $_SESSION requires session_start() before use. session_register function returns boolean value and $_SESSION returns string value session_register() function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. We know that Webpages ar...
Comments
Post a Comment