简体   繁体   中英

Wordpress - Using functions outside Wordpress

I using the following code for an external php file which is being executed through curl:

    <?php
include ('wp-config.php'); //Not sure how to do it.

if (!empty($_POST['username']) && !empty($_POST['password'])) { 
        $username= $_POST['username'];
        $password= $_POST['password'];
$url = 'http://www.example.com/RequestDetails?UserId='.$username.'&pass='.$password;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL,$url);
    $resultauth=curl_exec($ch);
    curl_close($ch);
    $result = file_get_contents($url);
    /*----Working fine till now*/

if ($results == 'authenticated user'){
$auth_options = get_option( 'user_options' );
$auth_options['user'][$username] = array( 'verified'=>'pendingverified', 'timestamp'=> current_time( 'mysql' ) );
}
?>

The $auth_options['user'][$username] is not working and I guess it is because this file is not linked to wordpress.

Does anybody know why that happens? Did I forget to include something?

尝试包含 wp-load.php

include ( 'wp-load.php' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM