Using curl_init function in PHP (1/4)_PHP tutorial
The code is as follows:
$ch = curl_init();
$c_url = 'http://www.bkjia.com;
$c_url_data = "product_&type=".$type."";
curl_setopt($ch, curlopt_url,$c_url);
curl_setopt($ch, curlopt_post, 1);
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_postfields, $c_url_data);
echo $result = curl_exec($ch);
curl_close ($ch);
unset($ch);
Using curl in php tutorial
posted on September 14th, 2008 under php
Original (English) address: http://www.phpit.net/article/using-curl-php Copyright Statement: Attribution-Non-Commercial Use-No Derivatives 2.0
Summary:
In this article, we mainly explain the knowledge of php_curl library and teach you how to better use php_curl.
Introduction
You may encounter this problem in your PHP script code: How to get content from other sites? There are several solutions here; the simplest is to use the fopen() function in PHP, but the fopen function does not have enough parameters to use, such as when you want to build a "web crawler" and want to define the client description of the crawler (ie , firefox), obtain content through different request methods, such as post, get; etc. These requirements cannot be achieved with the fopen() function.
In order to solve the problem we raised above, we can use PHP's extension library-curl. This extension library is usually included in the installation package by default. You can use it to obtain the content of other sites or do other things.
Note: These two pieces of code require the support of the php_curl extension library. Check phpinfo(). If curl support is enabled, it means that the curl library is supported.
1. Enable curl library support in PHP under Windows:
Open php.ini and remove the ; sign before extension=php_curl.dll.
2. Enable curl library support in PHP under Linux:
When compiling php, add –with-curl
after ./configure
In this article, we will take a look at how to use the curl library and see its other uses, but next, we will start with the most basic usage
Basic usage:
In the first step, we create a new curl session through the function curl_init(). The code is as follows:
// create a new curl resource
$ch = curl_init();
?>
We have successfully created a curl session. If we need to obtain the content of a URL, the next step is to pass a URL to the curl_setopt() function, code:
// set url and other appropriate options
curl_setopt($ch, curlopt_url, “http://www.google.com/”);
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
