There are several small issues in the tangle

Source: Internet
Author: User
Several problems exist. 1) the ifelse statement of PHP cannot be nested with ifelse, for example, ifa & gt; B & nbsp ;{& nbsp; $ c =$ _ post ['ABC']; & nbsp; if $ c & lt; 3 & nbsp
1) PHP's if else statement cannot be nested if else,
For example, if a> B
{
$ C = $ _ post ['ABC'];
If $ c <3
{
$ D = 4;
}
}
PHP and above are not allowed. how do you deal with this complicated if else?

2) I have written some other pages. how can I ensure that I can access them only after logging on?


3) does db_connect.php use include, require_once, and include_once on the database connection page?


4) if PDO is used, $ dbh = new PDO ('mssql: host = 192.168.x.x; dbname = ABCD', $ username, $ pwd );

Do you want to release this PDO at the end? How can I release it? (A lot of things need to be released, such as session, session_start () and session_destroy (). What about PDO?

Thank you.


------ Solution --------------------
1. of course, nesting is allowed. your code has syntax problems (if condition brackets cannot be omitted)
PHP code
  $ B) {$ c =$ _ post ['ABC']; if ($ c <3) {$ d = 4 ;}}?>
------ Solution --------------------
1: nesting allowed

2: Check the session usage. Check the session.

3: actually. If you are worried about repeated inclusion. Then use require_once ()/include_once ()

4: If your connection is not permanent. You do not need to disable it. Because php will automatically shut down when the script ends.

------ Solution --------------------
You can use session or cookie for user authentication.

$ Dbh = new PDO ('mssql: host = 192.168.x.x; dbname = ABCD', $ username, $ pwd );
It does not need to be released and will be released automatically when the program ends.
$ Dbh = null;

------ Solution --------------------
The other answers are similar.

2) I have written some other pages. how can I ensure that I can access them only after logging on?

After logging on, you must determine whether the account is authorized. you can pass the global SESSION or COOKIE to determine whether the account is authorized,
These contents are output through php, for example, include some encrypted data or echo the entire html code, depending on how much content you need to provide to the user for processing.

For example

If (isset ($ _ SESSION ['islogin']) {
// Output Content
} Else {
// Invalid view
}

Sessions are secure because they are stored on the server. of course, mixed cookies are also common usage. if necessary, you can add a timestamp to determine if the time exceeds the limit ..
------ Solution --------------------
1: generally, it is not recommended to Judge multiple nesting (whether it is a loop or a general if 'else). if multiple nesting is required, check whether other simplification can be used. for example: switch
4: database connection. you can create a single-piece mode to ensure that only one database connection object exists.

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.