The dialogue on the Couch (iv) _php tutorial

Source: Internet
Author: User
There are many ways to change the skin of a cat ...

Of course, if your site is still running PHP3, you won't be able to use any of the code so far. But don't be frustrated-there's another solution available to PHP3 users. It is called Phplib, which provides a set of useful classes that allow you to increase the management of the session in your PHP3. You can install according to the instructions in the package, and you will also need to modify the "local.inc" profile to create your own classes.
As in PHP4, each time you initialize a session, you need to call the Page_open () function in advance. Phplib returns a default class named Example_session-you can modify this value in the "local.inc" file-it will be used in the following example:


$#@60;? Php

Page_open (Array ("Sess" =$#@62; "Example_session"));

? $#@62;

It is important to call Page_open () before any output is sent to the browser. In order to register your session variable, the following statement can do the work.
$#@60;? Php

Initializes a session Page_open (array ("Sess" =$#@62; "Example_session"));

Register a Session variable $sess-$#@62;register (username);

? $#@62;

Each page must also contain the corresponding page_close () function to confirm that the amount of change is saved in the database.

$#@60;? Php

Page_close ();

? $#@62;

In addition to these, most of the code is the same. Check out the Phplib version of the previous example:

$#@60;? PHP


//Initializes a session Page_open (array ("Sess" =$#@62; "Custom_session"));

//Register Session variable-note syntax
$sess-$#@62;register (username);
$sess-$#@62;register (STOCK1);
$sess-$#@62;register (STOCK2);
$sess-$#@62;register (STOCK3);
$sess-$#@62;register (STOCK4);

//connect MySQL $db = mysql_connect ("someserver.com", "Tom", "Jones");

//Select Database mysql_select_db ("stock_db", $db);

//Querying the database using SQL
$query = "Select Stock_pref1,stock_pref2,stock_pref3,stock_pref4
from User_info where Username= $username ";

$result = mysql_query ($query, $db);

//Fetch the stock code from the database and assign the value to the session variable
list ($stock 1, $stock 2, $stock 3, $stock 4) = Mysql_fetch_row ($result);

//Output
echo "Hi $usernam #@60;br$#@62;";
echo "Your selected stocks are:$#@60;br$#@62;";
echo "$stock 1$#@60;br$#@62;";
echo "$stock 2$#@60;br$#@62;";
echo "$stock 3$#@60;br$#@62;";
echo "$stock 4$#@60;br$#@62;";

//Generate page Rest code

//Save data to database

Page_close ();
? $#@62;

As you can see, once you put down the PHP4 version, it's not difficult to understand the Phplib version-when you know that the internal support for the session in PHP4 is largely based on the Phplib module, you won't be surprised. If you are interested, phplib actually in the management of the session, the identity authentication and permissions of the class more in-depth, it allows you in the database-based authentication management, to a user to allow or prohibit the processing of power-can look at the document on how to use these features examples.

Phplib also provides some interesting built-in functions.

Unregister (variable)

This news a total of 2 pages, currently on the 1th page 1 2


Allows you to unregister a variable from a special session. Note that in that case, the variable is not deleted, but its value will be lost at the end of the page because it is no longer saved to the database.

$#@60;? Php

Page_open (Array ("Sess" =$#@62; "Example_session"));

Register a variable $sess-$#@62;register (username);

Check if it's already registered.
if ($sess-$#@62;is_registered (username))
{
echo "Variable" username "is registered!$#@60;br$#@62;";
}
Else
{
echo "Variable" username "is unregistered!$#@60;br$#@62;";
}

Unregisters a variable $sess-$#@62;unregister (username);

Check if it has been unregistered if ($sess-$#@62;is_registered (username))
{
echo "Variable" username "is registered!$#@60;br$#@62;";
}
Else
{
echo "Variable" username "is unregistered!$#@60;br$#@62;";
}

Page_close ();

? $#@62;

is_registered (variable) returns TRUE if a session has already been registered, otherwise false is returned.

$#@60;? Php

Page_open (Array ("Sess" =$#@62; "Example_session"));

if ($sess-$#@62;is_registered (username))
{
echo "A session variable by the name" username "already
Exists ";
}
Else
{
$sess-$#@62;register (username);
}

Page_close ();

? $#@62;

Delete () releases the current session.

It is interesting to note that in Phplib's cookie mode, it is possible to start a new session after the call to delete (), set a new cookie on the client, and even re-register some variables from the previous session-- Can fundamentally change the session like flying. Of course, you do things like this, you need to make your life ... Get up!

The URL ($url) allows you to redirect the user to a new page.

Self_url () returns a reference to the URL of the current page, including php_self and query_string information.

So in the end, for those of you who unfortunately have an ISP that doesn't offer PHP4 and phplib-remember, it's always possible to simulate a session with good cookie technology. All you have to do is set up a cookie with information to keep the user's access to your site for long periods of time, and to process this information each and every time a user accesses a new page. It's primitive--but it works, and sometimes you can't kill a simple way to do something!

The patient left the hospital.

Patient: Wow, doctor--great! Thank you so much for everything!

Psychiatrist: No problem, Victor. I'd be happy to help you. Do you feel better now?

Patient: Oh, easy! When I first came in, the whole day looked grey and gloomy-and now, the view from the Awning window has never been better ...

Psychiatrist: Uh ... Victor... If I were you would be very careful outside, the handrail is a bit bad, where it may not be very safe.

Patient: Don't worry, doctor--like this day, I feel God ... St... Ah!!!

This news a total of 2 pages, currently on the 2nd Page 1 2


http://www.bkjia.com/PHPjc/532659.html www.bkjia.com true http://www.bkjia.com/PHPjc/532659.html techarticle There are many ways to change the skin of a cat ... Of course, if your site is still running PHP3, you won't be able to use any of the code so far. But don't be frustrated-there's another one available to PHP3 users ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.