Unreasonable profile user php. We remove the visual editor, choice of color scheme and other details in the WordPress admin area. Hide "Hot Keys"

General issues

Q: The profiler shows server activity, but does not show all requests and sessions.

A: Don't forget to press the Start button to start capturing sessions.

Q: I was able to connect to MySQL, but Sessions are not showing.

A: Neor Profile SQL works as a proxy server. This means that only sessions passing through the profiler can be shown. Your application (or site) should connect to the profiler just like a regular MySQL server. The profiler only uses TCP incoming connections. And then you will see the result in the Sessions tab.

Q: Why are requests with zero time in some sessions?

A: Zero-time queries are extremely fast with no latency. Such queries could be cached by the DBMS or are executed very quickly, for example, if you have a powerful server and well-optimized tables.

Q: What does% in time and duration mean in a session?

A:"Time%" is a fraction of the total session execution time. "Duration%" is the proportion of the longest request in the session (the ratio to the longest request).

Q: I use JetProfiler and it is easier to set up.

A: JetProfiler receives information from MySQL server through the command "show status" and cannot get all the information on the server, since it works discretely. Neor Profile SQL shows absolutely all database queries. And that requires configuring your application to route the flow of requests through the profiler.

Q: The Profile button in the SQL tab does not show the result

A: The profiling feature in the SQL editor works through the SHOW PROFILES command, which has been added to MySQL Community Server since version 5.0.37. Check your MySQL server version.

Q: Can I make the profiler console-based?

A: For the console, use a bunch of DBMS logs and tail, or special console tools, of which there are quite a few. Neor Profile SQL is a windowing OS application that is intended to be hosted on the system by a developer.

Q: The profiler works, but why doesn't it display the main statistics graph?

A: The main graph uses the SHOW STATUS command for the main server. You may not have permission to run this command on the server. Make sure the rights to this command are available.

Q: How do I run the installer in quiet mode?

A: sqlprofiler-4.1.1.exe / S / D: C: Program Files (x86) Neor Profile SQL

Windows

Q: How to check the Profiler connection?

A: Use the MySQL console client to connect to the profiler. If you see your session in the Sessions tab, it means that everything is configured correctly.
For example:
Then execute a simple SQL command:
show tables;
And see what happened in the Sessions tab in the profiler.

Linux

Q: Can't connect via localhost.

A: Linux tries to associate localhost with a socket connection, but Neor Profile SQL only works with TCP connections. Set the server address in the profiler to 127.0.0.1 instead of localhost. Do the same in your application settings.
For example:
mysql --host = 127.0.0.1 --user = LOGIN --password = PASSWORD --port = 4040

Q: I cannot connect to 127.0.0.1.

A: Check the connection type in your application. You can also use the local socket connection type, which does not require you to enter a port value.

Q: How do I install Neor Profile SQL under OpenSUSE?

A: At the moment we only support the DEB package that runs on Ubuntu, Debian and compatible Linux distributions... You can make an RPM file yourself and help by doing so.

Q: Why can't I intercept Sysbench queries?

A: The profiler only uses TCP incoming connections. Run Sysbench with host and port parameters:
sysbench --test = oltp --mysql-host = 127.0.0.1 --mysql-port = 4040--mysql-user = root --mysql-password = password prepare

Mac OS X

Q: The profiler cannot connect to the MAMP MySQL server.

A: Problem network connection in MySQL config:

  1. MAMP
    Free version- copy the standard MySQL config to the folder
    /Applications/MAMP/conf/my.cnf
    Pro version - open menu FILE - EDIT - MySQL template
  2. in my.cnf config remove the skip-networking line
  3. in the Profiler Settings change the database host address from localhost to 127.0.0.1

Changing the MySQL port in your script

In Neor Profile SQL, the default port is 4040. To collect SQL queries you must change the default values ​​for MySQL connection to host and port 3306 in your script. Below are examples of how to do this.

string connStr = " server = 127.0.0.1; port = 4040; database = YOUR_DATABASE; user = YOUR_USER; password = YOUR_PASSWORD; ";
http://dev.mysql.com/doc/refman/5.1/en/connector-net-tutorials-intro.html


Port change in popular CMS

Wordpress

File: wp-config.php
Code: define ("DB_HOST", "localhost :4040 ");

PrestaShop

File: config / settings.inc.php
Code: define ("_ DB_SERVER_", "localhost :4040 ");

OpenCart

File: config.php
Code: define ("DB_HOSTNAME", "localhost :4040 ");

I've already written WordPress users (see the link). But like any tool (except for the sledgehammer) Adminimize is not ideal and it cannot completely remove everything, although this is thanks only to the Vorpress programmers.

This post was born spontaneously, thank you guest Blow. The essence of his question was as follows (rather a series of questions):

1. How to hide the "Color Scheme Selection" for the user?

2. How to hide "Keyboard Shortcuts" and "Visual Editor" in WordPress dashboard?

I'll get straight to the point. Using this method, you can hide any elements for the user in his profile and on other pages as well. The easiest way is to edit the display file!

For "Profile" this is the file user-edit.php which lies in the folder wp-admin. You need to edit it very carefully, otherwise you can "pay off" well for your experiments.

Solution (unified):

1. Download the file to your PC and make a copy of it (safe ....)

2. We are looking for the Html-code, which is responsible for displaying the information we need.

3. Carefully comment on it and "fill" it back with replacement.

Now practice (edit User-edit.php):

Honestly, I don't remember which version of WP I have on the experimental site, but definitely not lower than 2.8.2.

First, I downloaded the file to my PC and using the Viewer Chrome code"I looked at the code itself, and found the code I needed in Notepad ++.

(two dashes on each side "-")

1. Hide the "Visual editor"

Change to code:

—>

ps: do not copy this code, but change it for yourself - there is a high probability of errors !!!

2. Hide the "Select color scheme".

I hope you noticed the difference between the codes - you added 7 characters in total. To hide this item, we are looking for if (count ($ _ wp_admin_css_colors)> 1) and comment under the line all the code between before

3. Hide the "Hot Keys".

In the second lesson, we will write two more classes and finish the inner part of the script completely.

Plan

The goal of this tutorial series is to create a simple application that allows users to register, sign in, sign out, and change settings. The class that will contain all the information about the user will be called User and it will be defined in the User.class.php file. The class that will be responsible for entering / exiting will be called UserTools (UserTools.class.php).

A little about class naming

It is a good practice to name the files with the description of the class the same name as the class itself. This makes it easy to determine the purpose of each file in the class folder.

It is also common to add .class or .inc at the end of the class file name. Thus, we clearly define the purpose of the file and can use .htaccess to restrict access to these files.

User Class (User.class.php)

This class will define each user. As this application grows, the definition of "User" may change significantly. Fortunately, OOP programming makes it easy to add additional user attributes.

Constructor

In this class, we will use a constructor - this is a function that is automatically called when another copy of the class is created. This allows us to automatically publish some of the attributes after creating the project. In this class, the constructor will take a single argument: an associative array that contains one row from the users table of our database.

require_once "DB.class.php"; class User (public $ id; public $ username; public $ hashedPassword; public $ email;
public $ joinDate;
//The constructor is called when a new object is created// Takes an associative array with the DB row as an argument. function __construct ($ data) ($ this-> id = (isset ($ data ["id"]))? $ data ["id"]: ""; $ this-> username = (isset ($ data [" username "]))? $ data [" username "]:" "; $ this-> hashedPassword = (isset ($ data [" password "]))? $ data [" password "]:" "; $ this- > email = (isset ($ data ["email"]))? $ data ["email"]: ""; $ this-> joinDate = (isset ($ data ["join_date"]))? $ data [" join_date "]:" ";)
public function save ($ isNewUser = false) (// create a new database object. $ db = new DB (); // if the user is already registered and we "re // just updating their info. if (! $ isNewUser ) (// set the data array $ data = array ("username" => "" $ this-> username "", "password" => "" $ this-> hashedPassword "",
"email" => "" $ this-> email "");
// update the row in the database $ db-> update ($ data, "users", "id =". $ this-> id); ) else (// if the user is being registered for the first time. $ data = array ("username" => "" $ this-> username "", "password" => "" $ this-> hashedPassword "" , "email" => "" $ this-> email "", "join_date" => "" ".date (" Ymd H: i: s ", time ())." ""); $ this-> id = $ db-> insert ($ data, "users"); $ this-> joinDate = time ();) return true; ))?>

Explanation

The first part of the code, outside the class zone, provides the connection of the class to the database (since there is a function in the User class that requires this class).

Instead of class variables “protected” (used in lesson 1) we define them as “public”. This means that any code outside the class has access to these variables when working with the User object.

The constructor takes an array where the columns in the table are keys. We set the class variable using $ this-> variablename. In the example of this class, we first check if the value of a specific key exists. If so, then we set the class variable to this value. Otherwise, it is an empty string. The code uses a short form of notation for the if turnover:

$ value = (3 == 4)? "A": "B";

In this example, we check if 3 equals four! If yes - then $ value = “A”, no - $ value = “B”. In our example, the result is $ value = “B”.

We save information about users in the database

The save function is used to make changes to the database table with the current values ​​in the User object. This function uses the DB class we created in the first tutorial. Using class variables, the $ data array is set. If the user data is being saved for the first time, then $ isNewUser is passed as $ true (default is false). If $ isNewUser = $ true then the insert () function of the DB class is called. Otherwise, the update () function is called. In both cases, information from the user object will be saved in the database.

UserTools.class.php class

This class will contain functions that are relevant to users: login (), logout (), checkUsernameExists (), and get (). But with the expansion of this application, you can add many more.

//UserTools.class.php require_once "User.class.php"; require_once "DB.class.php";
class UserTools (
// Log the user in. First checks to see if the // username and password match a row in the database. // If it is successful, set the session variables // and store the user object within.
public function login ($ username, $ password)
{
$ hashedPassword = md5 ($ password); $ result = mysql_query ("SELECT * FROM users WHERE username =" $ username "AND password =" $ hashedPassword ""); if (mysql_num_rows ($ result) == 1) ($ _SESSION ["user"] = serialize (new User (mysql_fetch_assoc ($ result))); $ _SESSION ["login_time"] = time (); $ _SESSION ["logged_in "] = 1; return true;) else (return false;))
// Log the user out. Destroy the session variables. public function logout () (unset ($ _ SESSION ["user"]); unset ($ _ SESSION ["login_time"]); unset ($ _ SESSION ["logged_in"]); session_destroy ();) // Check to see if a username exists. // This is called during registration to make sure all user names are unique. public function checkUsernameExists ($ username) ($ result = mysql_query ("select id from users where username =" $ username ""); if (mysql_num_rows ($ result) == 0) (return false;) else (return true;)
}
// get a user // returns a User object. Takes the users id as an input public function get ($ id) ($ db = new DB (); $ result = $ db-> select ("users", "id = $ id"); return new User ($ result );))
?>

Login () function

The login () function is self-explanatory. It takes the user's $ username and $ password arguments and checks if they match. If everything matches, creates a User object with all the information and stores it in the session. Please note that we are only using PHP's serialize () function. It creates a saved version of the object that can be easily undone using unserialize (). Also, the login time will be saved. This can be used in the future to provide users with information about the duration of their stay on the site.

You may also notice that we are setting $ _SESSION ["logged_in"] to 1. This allows us to easily check if the user is logged in on each page. It is enough to check only this variable.

Logout () function

Also a simple function. PHP's unset () function clears variables in memory, while session_destroy () will delete the session.

CheckUsernameExists () Function

Anyone who knows English will easily understand the function. It simply asks the database if a similar login is used or not.

Get () function

This function takes a unique user id and makes a query to the database using the DB class, namely the select () function. It will take an associative array with a number of user information and create a new User object, passing the array to the constructor.

Where can you use it? For example, if you create a page that should display specific user profiles, you will need to dynamically grab this information. This is how you can do it: (let's say url http://www.website.com/profile.php?userID=3)

// note: you will have to open up a database connection first. // see Part 1 for further information on doing so. // You "ll also have to make sure that you" ve included the class files.
$ tools = new UserTools (); $ user = $ tools-> get ($ _ REQUEST ["userID"]); echo "Username:". $ user-> username. ""; echo "Joined On:". $ user-> joinDate. "";

Easily! Truth?

Server-side finishing touch: global.inc.php

global.inc.php is required for every page on the site. Why? This way we will place all the usual operations that we need on the page. For example, we'll start session_start (). The DB connection will also open.

require_once "classes / UserTools.class.php";
require_once "classes / DB.class.php";
// connect to the database $ db = new DB (); $ db-> connect ();
// initialize UserTools object $ userTools = new UserTools (); // start the session
session_start ();
// refresh session variables if logged in if (isset ($ _ SESSION ["logged_in"])) ($ user = unserialize ($ _ SESSION ["user"]); $ _SESSION ["user"] = serialize ($ userTools-> get ($ user-> id));)?>

What is he doing?

There are several things going on here. First of all, we open a connection to the base.

After connecting, we start the session_start () function. The function creates a session or continues the current one if the user is already logged in. Since our application is designed for users to log in / out, this feature is required on every page.

Next, we check if the user is logged in. If so, we'll update $ _SESSION ["user"] to display the most recent user information. For example, if a user changes his email, the old one will be stored in the session. But this won't happen with auto update.

This concludes the second part! Expect a final lesson on this topic tomorrow.

All the best!

I would like to devote this lesson to creating a personal profile for registered users (addition to the lesson Creating user registration on the site). Now users can add their avatar, change first and last name, add place of residence and birthday. To do this, the table users add some fields:

Now let's create a profile page profile.php and add on the page index.php link to it

Echo "
My profile"; Now the code of the profile.php page itself

Profile<?php echo $login; ?>

Profile



"; echo" ". $ array [" name_user "]." ". $ array [" lastname "]."
"; switch ($ array [" birthdate_month "]) (// Turn the month number into the name case" 1 ": $ month =" January "; break; case" 2 ": $ month =" February "; break; case" 3 ": $ month =" March "; break; case" 4 ": $ month =" April "; break; case" 5 ": $ month =" May "; break; case" 6 ": $ month =" June "; break; case" 7 ": $ month =" July "; break; case" 8 ": $ month =" August "; break; case" 9 ": $ month =" September "; break; case" 10 " : $ month = "October"; break; case "11": $ month = "November"; break; case "12": $ month = "December"; break;) echo "Registration date:". $ array [" reg_date "]."
"; echo" Sex: ". $ array [" sex "]."
"; echo" Birthday: ". $ array [" birthdate_day "]." ". $ month." ". $ array [" birthdate_year "]."
"; echo" Country: ". $ array [" country "]."
"; echo" City: ". $ array [" city "]."
"; if ($ _ GET [" id "] == $ id_user) (// Only the owner can edit the profile echo" Edit profile";)) else (print<<Entrance:
Login: Password:
registrationPassword recovery HERE; )?>

Naturally, going to this page, we will see a standard avatar noAvatar.jpg and perhaps the first and last name, if the user specified them during registration, the rest of the items will be empty. At the very end of this page there is a link to the edit profile page edit.php... The code for this page is very lightweight and consists of data entry forms. Due to the rather large volume, I will not cite it in full here, but I will cite only a part, it will be possible to completely take it in the source files.

All other forms are similar and will refer to one handler save_edit.php, which will make changes to the database. It also has a fairly large code, and I will not give it here either, but just tell you a little what happens in it (you can also find the complete code in the source files). First of all, we create an avatar, if the user has uploaded it, of course, otherwise we leave the standard one. If so, then first of all we upload to the folder avatars(by the way, create this folder and give it write permissions 755) after checking with the allowed extensions. Then a new image is created in the format depending on the selected mode: $ rezim = 1 a square picture is created, $ rezim = 2 the picture is proportional to the original. You also need to set the width of the created image. $ w and quality $ quality... We save the created image in jpg format using the function imagejpeg and generate a random name for it. Now you need to delete the old image and update the database with a new one. That's all with the images.

All other items of this file are designed to update personal data about the user and represent simple queries to the database to update the fields. Before the upgrade, the existence of incoming variables and their safety are checked using stripslashes and htmlspecialchars... If the update is successful, then we immediately redirect the user to the profile page.
Now we will make it so that the logged in user can see all other registered users. To do this, we will create a page user.php, which will display all users in a loop.