The sixth day of php practice. I learned how to create a background page today. if it fails, it will not be displayed. Php: The following code can block php attention-level errors, that is, it throws any non-attention errors [php] error_reporting (E _ learned to create a background page today and will not be displayed if it fails.
Php: The following code can block php attention-level errors, that is, throw any non-attention errors.
[Php] error_reporting (E_ALL &~ E_NOTICE );
Error_reporting (E_ALL &~ E_NOTICE );
You can use $ _ SESION after enabling session.
Session is something stored on the server. After the session is started, a session ID is sent to the browser, which is cookies.
[Php] session_start ();
Session_start ();
It doesn't matter if the browser disables cookies. you can write the session to the URL.
[Php] session_name. '='. session_id ()
Session_name. '='. session_id () is attached with the adminAction that I have written. only the login function is supported.
[Php] /**
*
**/
Class adminAction extends Action
{
Protected $ db = '';
Function _ construct ()
{
// Code...
/// $ Smarty-> force_compile = true;
/* $ This-> db = new MySQL ("127.0.0.1", "root", "1234", "myly", "data ");
$ This-> db-> table ('data ');*/
$ This-> db = MySQL: getClass ();
// Var_dump ($ this-> db );
$ This-> db-> connect ("127.0.0.1", "root", "1234", "myly ");
$ This-> db-> table ('user ');
Parent: :__ construct ();
}
Public function index ()
{
If ($ this-> is_login ()){
Echo "script window. location. href = 'admin. php? M = admin & a = admin'; script ";
} Else {
Echo "script window. location. href = 'admin. php? M = admin & a = login '; script ";
}
}
Private function is_login ()
{
Return $ _ SESSION ['login'];
}
Public function login ()
{
If (! Empty ($ _ POST ['username']) &! Empty ($ _ POST ['password']) {
$ UserName = $ _ POST ['username'];
$ Password = md5 ($ _ POST ['password']);
/* Var_dumP ($ _ POST );
Var_dump ($ password );
Var_dump ($ password );*/
If ($ _ SESSION ['userdata'] = $ this-> db-> where ("userName = '{$ userName}' and password = '{$ password }'") -> fine ()){
Echo "script window. location. href = 'admin. php? M = admin & a = admin'; script ";
$ _ SESSION ['login'] = true;
} Else {
Echo "logon failed ";
}
}
$ This-> display ();
}
Public function ulogin ()
{
Echo "script window. location. href = 'admin. php? M = admin & a = login '; script ";
Unset ($ _ SESSION );
}
Public function admin ()
{
If (! $ This-> is_login ()){
Echo "script window. location. href = 'admin. php? M = admin & a = login '; script ";
}
// Var_dump ($ _ SESSION );
$ This-> assign ('username', $ _ SESSION ['userdata'] ['username']);
$ This-> display ();
}
Function add (){
/* Var_dump ($ this-> db
-> Data (
Array ('username' => 'admin ',
'Password' => md5 ('admin '),
'Time' => time ()
))
-> Add ());
*/
}
}
?>
/**
*
**/
Class adminAction extends Action
{
Protected $ db = '';
Function _ construct ()
{
// Code...
/// $ Smarty-> force_compile = true;
/* $ This-> db = new MySQL ("127.0.0.1", "root", "1234", "myly", "data ");
$ This-> db-> table ('data ');*/
$ This-> db = MySQL: getClass ();
// Var_dump ($ this-> db );
$ This-> db-> connect ("127.0.0.1", "root", "1234", "myly ");
$ This-> db-> table ('user ');
Parent: :__ construct ();
}
Public function index ()
{
If ($ this-> is_login ()){
Echo "script window. location. href = 'admin. php? M = admin & a = admin'; script ";
} Else {
Echo "script window. location. href = 'admin. php? M = admin & a = login '; script ";
}
}
Private function is_login ()
{
Return $ _ SESSION ['login'];
}
Public function login ()
{
If (! Empty ($ _ POST ['username']) &! Empty ($ _ POST ['password']) {
$ UserName = $ _ POST ['username'];
$ Password = md5 ($ _ POST ['password']);
/* Var_dumP ($ _ POST );
Var_dump ($ password );
Var_dump ($ password );*/
If ($ _ SESSION ['userdata'] = $ this-> db-> where ("userName = '{$ userName}' and password = '{$ password }'") -> fine ()){
Echo "script window. location. href = 'admin. php? M = admin & a = admin'; script ";
$ _ SESSION ['login'] = true;
} Else {
Echo "logon failed ";
}
}
$ This-> display ();
}
Public function ulogin ()
{
Echo "script window. location. href = 'admin. php? M = admin & a = login '; script ";
Unset ($ _ SESSION );
}
Public function admin ()
{
If (! $ This-> is_login ()){
Echo "script window. location. href = 'admin. php? M = admin & a = login '; script ";
}
// Var_dump ($ _ SESSION );
$ This-> assign ('username', $ _ SESSION ['userdata'] ['username']);
$ This-> display ();
}
Function add (){
/* Var_dump ($ this-> db
-> Data (
Array ('username' => 'admin ',
'Password' => md5 ('admin '),
'Time' => time ()
))
-> Add ());
*/
}
}
?>
Login.html used to submit the form
[Html]
Waterfall Stream message board background login
Waterfall Stream message board background login
Admin.html
[Html]
Welcome <{$ userName}>
Welcome <{$ userName}>
This is my login function.
Modified mysql. class. php and added a function fine, so that the returned array is one-dimensional, which is more convenient.
[Php]/**
+ ----------------------------------------------------------
* Obtain a single record of a data table and return a one-dimensional array
+ ----------------------------------------------------------
* @ Access public
+ ----------------------------------------------------------
* @ Param
+ ----------------------------------------------------------
*/
Public function fine (){
$ Select_ SQL = 'select ';
$ Fields = isset ($ this-> query_list ['fields'])? $ This-> query_list ['fields']: '*';
$ Select_ SQL. = $ fields;
$ Select_ SQL. = 'from'. $ this-> query_list ['table']. ''';
Isset ($ this-> query_list ['join'])? ($ Select_ SQL. = $ this-> query_list ['join']): '';
Isset ($ this-> query_list ['where'])? ($ Select_ SQL. = 'where'. $ this-> query_list ['where']): '';
Isset ($ this-> query_list ['group'])? ($ Select_ SQL. = 'group by'. $ this-> query_list ['group']): '';
Isset ($ this-> query_list ['having '])? ($ Select_ SQL. = 'MySQL having '. $ this-> query_list ['having']): '';
Isset ($ this-> query_list ['order'])? ($ Select_ SQL. = 'Order by'. $ this-> query_list ['order']): '';
Isset ($ this-> query_list ['limit'])? ($ Select_ SQL. = '1,1 '):'';
// Echo'
-----> '. $ Select_ SQL.' <---------
';
Return $ this-> query ($ select_ SQL) [0];
}
/**
+ ----------------------------------------------------------
* Obtain a single record of a data table and return a one-dimensional array
+ ----------------------------------------------------------
* @ Access public
+ ----------------------------------------------------------
* @ Param
+ ----------------------------------------------------------
*/
Public function fine (){
$ Select_ SQL = 'select ';
$ Fields = isset ($ this-> query_list ['fields'])? $ This-> query_list ['fields']: '*';
$ Select_ SQL. = $ fields;
$ Select_ SQL. = 'from'. $ this-> query_list ['table']. ''';
Isset ($ this-> query_list ['join'])? ($ Select_ SQL. = $ this-> query_list ['join']): '';
Isset ($ this-> query_list ['where'])? ($ Select_ SQL. = 'where'. $ this-> query_list ['where']): '';
Isset ($ this-> query_list ['group'])? ($ Select_ SQL. = 'group by'. $ this-> query_list ['group']): '';
Isset ($ this-> query_list ['having '])? ($ Select_ SQL. = 'MySQL having '. $ this-> query_list ['having']): '';
Isset ($ this-> query_list ['order'])? ($ Select_ SQL. = 'Order by'. $ this-> query_list ['order']): '';
Isset ($ this-> query_list ['limit'])? ($ Select_ SQL. = '1,1 '):'';
// Echo'
-----> '. $ Select_ SQL.' <---------
';
Return $ this-> query ($ select_ SQL) [0];
}
Bytes. Php: The following code shields php attention-level errors, that is, it throws any non-attention errors [php] error_reporting (E _...