I propose to talk a little about the PHP programming language, and specifically touch on the topic of the extension CURL, i.e. the ability to interact with different servers using different protocols from the PHP script itself.
Before proceeding with the consideration of curl, I want to remind you that we have already touched on the PHP language, for example, in the material about uploading to Excel in PHP or the ability to authenticate in PHP, and now let's talk about the ability to send requests to PHP.
CURL is a PHP function library with which you can send requests, such as HTTP, from a PHP script. CURL supports protocols such as HTTP, HTTPS, FTP and others. You can send HTTP requests using the GET, POST, PUT methods.
CURL can be useful in cases where you need to call a remote script and get the result or just save the HTML code of the page being called, in general, everyone can find their own use, but the point is that you can send requests during the execution of the script.
In order to use the CURL library, you need to include it accordingly.
Note! We'll use PHP 5.4.39 on Windows 7 as an example, and Apache 2.2.22 as our Web server.
The first thing to do is copy the libraries ssleay32.dll, libeay32.dll, libssh2.dll they are located in the directory with PHP, in the Windows system directory, namely in C:\Windows\System32.
Then, in php.ini, connect the php_curl.dll library, i.e. uncomment the following line
Library not connected
;extension=php_curl.dllLibrary connected
Extension=php_curl.dll
That's it, restart Apache, call the phpinfo () function and in case of a successful connection, you should have a curl section
If it is not there, then this means only one thing, that the library did not load, the most common reason for this was that the above DLLs were not copied to the Windows system directory.
In this example, we will simply request a remote page via the HTTP GET method and display its content on the screen.
We have a test directory in it, 2 PHP files are test_curl.php and test.php, where test_curl.php is the script where we will use curl, and test.php is a remote script that we will call. I commented the code in detail.
test_curl.php code
test.php code
Heading 1Н1>"; break; case 2: echo "<Н2>Heading 2Н2>"; break; case 3: echo "<Н3>Heading 3Н3>"; break; ) ) ?>
As a result, if you run test_curl.php, you will see the inscription “Heading 1” on the screen, you can experiment with passing id parameters ( in this case 2 or 3).
Now let's try to call the script and get the result in order to process it later, for example, let's use the POST method. Leave the file names the same.
test_curl.php code
test.php code
And if we run test_curl.php, then 111 will be displayed on the screen, i.e. 1.11 resulting from the call to the remote script, multiplied by 100.
Now let's talk about functions and their constants.
You can see more about CURL functions and constants for them on the official PHP website -
Pair of glasses...
PHP doesn't have built-in import framework like python, java or .net. There are several ways to use libraries in PHP.
compile them into PHP binary. This is the most advanced way and is usually not desirable unless you have special needs.
Install them as PHP modules on the server and enable them in PHP.ini. From a PHP programmer's point of view, these extensions are part of PHP - always available. It's just easier to add and remove without having to rebuild PHP itself.
Install the PHP code on the server somewhere and include() it in your PHP script.
Save a copy of the library to your project and include it in your PHP script.
Page At a basic level, the code is either part of the interpreter (static or dynamic) or it's plain old PHP code that includes() ed in your project.
For your purposes, I can only suggest that you stick with the standard PHP distribution (choose a good Linux OS and use that PHP). Then almost all the libraries you'll need at the interpreter level are available as add-on packages, and the complexity of that is left to those who do it every day.
On RedHat/Centos you can run:
yum install php php-memcached php-gd php-pecl
Page As for all the other libraries you might want to use, it's probably best to use a good PHP framework that will take care of all this for you.
Some examples:
(not in any order, just the ones that come to mind)
Provided you've used the standard approach of using RPM or similar to manage the compiled ones in the PHP and extensions aspects, then a good robust framework will take care of including all of your additional PHP library code that you need.
What the end result is: You are focused on delivering the product, not on the entire infrastructure that you would otherwise have to learn and invent.
The php.ini page is parsed and run on PHP startup (each time for command line, once per server run in apache). It defines many settings, includes many modules, configures those modules, and so on.
In fact, you can override some settings in php.ini with PHP's ini_set() function. However, this only works for some settings. Others must be set prior to running the script.
When running under apache, you can add lines to .htaccess directives and
(please correct my syntax and remove this note if it's wrong)
Page In response to your question #6 about your own library and the best way to package it, I suggest you first evaluate the need for a library. And if you really do something, find out the most common way people do it. If it's a simple library, then a .php file with a good website is enough.
Page Maybe a bit rambling, but I hope this points you in the right direction.
Igor Guzey
This is not an exact and final instruction for action using the correct terms and best options. It is rather a log of the current problem.
As usual, we start training on the local computer, which, of course, works under Windows. More precisely Windows XP SP2. Next, we will connect GD2 in PHP configured through ports or manually built under FreeBSD.
We find in the distribution:
\php-4.3.9-Win32.zip\php-4.3.9-Win32\extensions\
php_gd2.dll library, i.e. version 2.
and copy php_gd2.dll to c:\windows
in the file c:\windows\php.ini we find the line extension=php_gd2.dll and remove the comment.
Reboot Apache. Everything.
If you naively first remove the comment in php.ini and think that this is enough, then after restarting Apache, a diagnostic will appear:
"Unable to load dynamic library "./php_gd.dll" - The specified module could not be found."
More precisely, not only PHP, but in general everything (php, MySQL, Apache, ...) was configured using ports.
# cd /usr/ports/lang/php4-extensions # make config add a checkmark: "GD library support" # make deinstall # make reinstall # apachectl -k graceful soft restart or # apachectl restart hard restart
In this case, preliminary work is required to prepare JPEG and ZLIB
Possible options
key | VAL$val) echo " |
---|---|
$key | $val"; ?> |
When installing the JPEG library, after "make" the "make install" command was made with the expectation that new files will go to /usr/local and then automatically be found there
# ./configure --with-mysql --with-apache=/usr/dist/apache_1.3.37 --enable-memory-limit --with-gd --with-jpeg-dir --with-zlib-dir= /usr/ports/archivers/php4-zlib/work/php-4.4.4/ext/zlib/modules
But for some reason the JPEG didn't connect. There was no negative diagnosis and no result.
Foolishly, I poked like a blind kitten trying to put it this way, that way. Either through everything built-in, then through the downloaded, then from the ports. All this disgrace was accompanied by unnecessary installations, which caused overlays due to which there were errors at the time of PHP installation:
# ./configure --with-mysql --with-apache=/usr/dist/apache_1.3.37 --enable-memory-limit --with-gd=/usr/local Thank you for using PHP. # make install /usr/dist/php-4.4.4/ext/gd/gd.c:1151: undefined reference to `gdImageRotate" this seems to indicate a directory for GD, but the diagnostics refers to the built-in directory. # ./configure - -with-mysql --with-apache=/usr/dist/apache_1.3.37 --enable-memory-limit --with-gd=/usr/local --with-jpeg-dir=/usr/local --with -png-dir=/usr/local --with-zlib-dir=/usr/ports/archivers/php4-zlib/work/php-4.4.4/ext/zlib/modules ... /usr/dist/php-4.4.4/ext/gd/gd.c:837: undefined reference to `gdImageColorMatch" /usr/dist/php-4.4.4/ext/gd/gd.c:1151 : undefined reference to `gdImageRotate" *** Error code 1
Trying to prepare all modules separately and point to them exactly.
The note: the adaptive version of the site is activated, which automatically adjusts to the small size of your browser and hides some details of the site for ease of reading. Enjoy watching!
Good day to all blog readers site on! For the last 2 months, my work for the company has been closely related to pure PHP (the use of frameworks and CMS is a taboo), I have already forgotten what Joomla is :) so it will be more appropriate to continue writing higher than ever.
Today we will talk about how files are connected in PHP. As you may have noticed, any website engine (Joomla, Wordpress, OpenCart, DLE and everything, everything, everything) consists of thousands of .php (and not only php) files and they all interact with each other, which actually forms the mechanism of work site.
Now forget about the engines and imagine another example: we have many pages on the site, each of them has the same menu, site header and footer. Naturally, we will not copy the same thing from file to file, otherwise it would have turned out to be an ancient HTML site from the 90s. At a minimum, we will break everything into 4 files:
In addition to the main page (index.php), for example, we can also have pages with a list of products (category.php) and pages of the products themselves (product.php). It will be convenient to connect the menu.php, header.php, footer.php files to these pages. Thanks to this approach, if we add a new menu item, then we will add it only once (in menu.php), and not 3 times (in index.php, product.php, category.php).
Therefore, the question arises: "How to attach a file in PHP?". There are 2 instructions in PHP for this purpose:
And their derivatives:
I draw your attention to the fact that include and require are not functions, they are so-called language constructs, so the brackets are not needed.
include And require- this is exactly the same, with the only difference being that if an error occurs (for example, if the specified file does not exist and it cannot be connected), include will return an error like Warning, after which the site will continue working, and require will issue a , which will completely stop further page loading.
That is, the require instruction is more radical and rigid. It's up to you to decide which is better to use, by and large it is recommended to always choose a more strict option, that is, require, but personally I find it more pleasant to type the word include :)
include_once and require_once do the same as include (include a file), but at the same time they make sure that each file is included no more than once. They are especially useful if several people are working on a project and you need to make sure that some file is not added several times.
Attention:
include_once And require_once- work slower and consume more RAM than include and require. This is logical and is due to the fact that they have to remember all the files that were connected and each time they connect, check whether this file has already been connected.
Let me illustrate how file connection works in PHP:
When including files (any, for example: html, txt, php, xml, etc.) PHP script, their content is stupidly inserted into the place of include. In other words, include (and I also mean require, since they are the same thing) is like copying (CTRL+C) code from somewhere and pasting (CTRL+V) into a file (for example, in product. php) and then saved and run as usual: http://yoursite.net/product.php
In order to distinguish the main files, such as product.php from those that we include in it (menu.php, header.php, footer.php), the included files are renamed as follows: menu.inc.php, header.inc.php , footer.inc.php. Thanks to this, when we go into the folder, we will immediately see where the main files are and where the auxiliary ones are.
Attention:
This technique (adding inc) is used only for visual convenience and does not carry any functional differences. But visual convenience is also very important, so try to always structure and do everything in the same style.
Remember the keyword? So in PHP there is such a wild thing as a return inside an include. I've never used it and never seen others use it, but it's possible, keep some.php example:
Include some.php:
// Output string: PHP ?>
Thank you all for your attention and have a great weekend!
By default, the extension for working with MySQL (php_mysql.dll library) is not connected to PHP and the corresponding functions are not available. To connect the library, you need to make changes to the php.ini configuration file and copy additional libraries to the c:/windows/system32 directory.
If you are using Apache version 2 and above, be sure to add the PHPIniDir directive to the Apache configuration file (httpd.conf), which allows you to specify the exact location of the php.ini file. After adding the directive, restart Apache and verify that the startup was successful.
PHPIniDir "c:/php"
Note that the forward slashes / are used when writing the path, which is not typical for Windows, which uses backslashes \\. The fact is that both Apache and PHP were originally designed to work on unix systems, where forward slashes are used. In order to avoid possible hard-to-diagnose problems, we strongly recommend using forward slashes in unix format in Apache and PHP configuration files.
This assumes that the php.ini configuration file is stored in the c:/php directory. To make sure that Apache found the php.ini configuration file, run the phpinfo() function.
echo phpinfo();
?>
Find the row value in the resulting purple tables "Configuration File (php.ini) Path". It should contain the path to the php.ini file used, including the file itself. If only a directory is listed on this line, it means that Apache could not find the php.ini file.
C:/php/php.ini // Correct - php.ini found and used
C:/windows/ // Wrong - php.ini not found
In earlier versions of Apache, there was no PHPIniDir directive, and as a result, there were a lot of errors related to the incorrect location of the php.ini file. For Apache version 1.3, php.ini must be located in the Windows system directory, usually: c:/Windows. Using the PHPIniDir directive in Apache version 2 solves this problem radically.
After you have made sure that Apache is using the correct php.ini, you can start editing it to connect the MySQL extension.
The extension_dir directive specifies the directory where the php extension libraries are located, including the php_mysql.dll library. If you installed php in the c:/php directory, then the extension libraries are usually located in the ext subdirectory (c:/php/ext). Check if this is the case and set the correct value of the extension_dir directive.
extension_dir = "c:/php/ext"
To do this, find the line in php.ini:
;extension=php_mysql.dll
And remove the comment symbol from it - a semicolon.
Extension=php_mysql.dll
If you have PHP connected to Apache as a module, then to connect the MySQL extension, you need to copy the additional library libmysql.dll from the c:/php directory to the c:/windows/system32 directory. If php is connected to Apache as a CGI application, then no additional library needs to be copied.
Reload Apache for all changes to take effect.
To verify that the MySQL library has successfully connected to PHP, run the phpinfo() function. Look through the "purple tables" and look for a section named MySQL. If such a section exists, it means that the extension has successfully connected.
Before you start checking the interaction between PHP and MySQL, make sure that the MySQL server is running for you. This can be done by opening the list of Windows services: "Start" | "Control Panel" | "Administration" | "Services". Find the service named MySQL and make sure it is in the running state (third column of the table).
The second way to make sure the MySQL server is running is to press the "Crtl" + "Alt" + "Del" buttons and in the "Processes" tab, find the process named mysqld.exe. Instead of the mysqld.exe process, the following processes can also run: mysqld-nt.exe, mysqld-max-nt.exe, mysqld-debug.exe.
$dblocation = "127.0.0.1" ;
$dbname = "test" ;
$dbuser = "root" ;
$dbpasswd = "" ;
$dbcnx = mysql_connect ($dblocation , $dbuser , $dbpasswd ); Request error
if (! $dbcnx )
{
echo ""
;
exit();
}
if (!
{
echo ""
;
exit();
}
if(! $ver )
{
echo "
exit();
}
echo mysql_result($ver , 0 );
?>
If the test is successful, then the version number of the MySQL server will be displayed. Otherwise, descriptions of the errors that occurred will be displayed on the screen.
All errors containing the phrase "Call to undefined function" point to an unconnected PHP extension. If such errors occur when working with MySQL functions, then this means that the PHP library for working with MySQL is not connected - php_mysql.dll
Error message example:
Fatal error: Call to undefined function mysql_connect()
For a solution to this problem, see the beginning of the article.
If everything is done correctly, but the MySQL extension does not connect and even the MySQL block is missing in the output of the phpinfo() function, then check the version of the libmysql.dll library located in c:/windows/system32.
The libmysql.dll library of the same name is also supplied with the MySQL server. However, these are different libraries, and if the MySQL library is located in the c:/windows/system32 directory, then PHP will not be able to connect the extension. The libmysql.dll library can be automatically copied to c:/windows/system32 when MySQL server is installed. The presence in the system directory of a library from an old version of PHP can also become an obstacle.
The script shown in the listing below is often used as a script for checking the interaction between PHP and MySQL on our site. Its differences from the similar php script given at the beginning of the article are the @ symbols before calling the mysql_connect() and mysql_select_db() functions. These characters are used to suppress error output to the browser. It is useful to use them on a live site on the Internet to prevent confidential information from being displayed in the browser, but when debugging scripts, it is not necessary to disable error output, because. it can make it difficult to diagnose the problem.
$dblocation = "127.0.0.1" ;
$dbname = "test" ;
$dbuser = "root" ;
$dbpasswd = "" ;
$dbcnx = @ mysql_connect ($dblocation , $dbuser , $dbpasswd ); Sorry, mySQL server is not available Unfortunately the database is not available. Request error
if (! $dbcnx )
{
echo "
exit();
}
if ( [email protected]
mysql_select_db ($dbname , $dbcnx ))
{
echo "
exit();
}
$ver = mysql_query("SELECT VERSION()");
if(! $ver )
{
echo "
exit();
}
echo mysql_result($ver , 0 );
?>
If a blank page is displayed as a result of the execution of this script, then, as a rule, this means that the php_mysql.dll library is not connected to PHP. To more accurately diagnose the problem, perform the following sequence of actions.
If, when executing the test php script, an error similar to the following is generated:
Can't connect to MySQL server on "127.0.0.1" (10061)
in C:\www\panel\htdocs\test.php on line 7
This indicates that the MySQL database server is not running. A more accurate diagnosis of this problem is given above in paragraph 1 of the subsection "Checking the interaction between PHP and MySQL".
Presence of the following error:
Warning: mysql_connect() :
Access denied for user "root"@"localhost" (using password: YES)
in C:\www\panel\htdocs\test.php on line 7
Indicates that you are trying to connect to a MySQL database with an incorrect password. Check the value of the $dbpasswd variable in the test script. By default, the MySQL server is installed with a blank root user password. If you set a password for the root user yourself, then add it to the $dbpasswd variable of the check script.
Any questions you may have about connecting to the PHP extension to work with, you can ask on our forum dedicated to installing and configuring Apache, PHP and extension libraries.
kayabaparts.ru - Entrance hall, kitchen, living room. Garden. Chairs. Bedroom