Wordpress - 在 Wordpress 之外使用函数
Wordpress - Using functions outside Wordpress
我将以下代码用于通过 curl 执行的外部 php 文件:
<?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' ) );
}
?>
$auth_options['user'][$username]
不工作,我猜这是因为这个文件没有链接到 wordpress。
有人知道为什么会这样吗?我是不是忘了添加一些东西?
尝试包含 wp-load.php
include ( 'wp-load.php' );
我将以下代码用于通过 curl 执行的外部 php 文件:
<?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' ) );
}
?>
$auth_options['user'][$username]
不工作,我猜这是因为这个文件没有链接到 wordpress。
有人知道为什么会这样吗?我是不是忘了添加一些东西?
尝试包含 wp-load.php
include ( 'wp-load.php' );