PHP CURL POST & GET Examples – Submit Form using PHP CURL


Sourabh Jain

In PHP CURL POST tutorial, I have explained how to send HTTP GET / POST requests with PHP CURL library.

Below are the examples covered in this article.
1) Send HTTP GET Request with CURL
2) Send HTTP POST Requests with CURL
3) Send Random User-Agent in the Requests
4) Handle redirects (HTTP 301,302)
5) Handle Errors.

Why we need PHP CURL ?
To send HTTP GET requests, simply we can use file_get_contents() method.

1
file_get_contens('http://hayageek.com')

But sending POST request and handling errors are not easy with file_get_contents().

Sending HTTP requests is very simple with PHP CURL.You need to follow the four steps to send request.

step 1). Initialize CURL session

1
$ch= curl_init();

step 2). Provide options for the CURL session

1
2
3
curl_setopt($ch,CURLOPT_URL,"http://hayageek.com");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//curl_setopt($ch,CURLOPT_HEADER, true); //if you want headers

CURLOPT_URL ->…

View original post 619 more words

Advertisements

Give Editor Access To WordPress Sidebar


If you want to give the Editor Role access to editing the sidebar and it’s contents.

The edit_theme_options capability should allow the user to edit the sidebar as described on this page : http://codex.wordpress.org/Appearance_Widgets_SubPanel

Code to add to functions.php

$role = get_role('editor'); 
$role->add_cap('edit_theme_options');

or, you can use Members plugin to create/manage other roles and modify the capabilities.

http://wordpress.org/plugins/members/

This should work to prevent editor accessing themes or menus

function custom_admin_menu(){

    $user =new WP_User(get_current_user_id());if(!empty( $user->roles)&& is_array($user->roles)){foreach($user->roles as $role)
            $role = $role;}if($role =="editor"){ 
       remove_submenu_page('themes.php','themes.php');
       remove_submenu_page('themes.php','nav-menus.php');}}

add_action('admin_menu','custom_admin_menu');