Bad Request, Missing required parameters Yii2 - php

I have some problem with GET request.
If I send GET request like a /api/v1/users/user-settings?key=model-manual-user-settings in my app,
I get response like this:
{"name":"Bad Request","message":"Missing required parameters: key", "code":0, "status":400, "type":"yii\\web\\BadRequestHttpException"}
Run method in my action
/**
* Получение пользовательских данных по ключу
*
* #param string $key Ключ пользовательских параметров
* #return array
*/
public function run($key)
{
$component = new UserSettingsComponent($key);
return $component->getSettingsWithParams();
}
Piece of yii2 log file:
2018-05-25 18:58:52 [127.0.0.1][1][tsdsfjgmllh43vfb264qimc3fv][error][yii\web\HttpException:400] yii\web\BadRequestHttpException: Missing required parameters: key in /var/www/arm/vendor/yiisoft/yii2/web/Controller.php:149
Stack trace:
#0 /var/www/arm/vendor/yiisoft/yii2/base/Action.php(88): yii\web\Controller->bindActionParams(Object(api\actions\users\user_settings\IndexAction), Array)
#1 /var/www/arm/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\Action->runWithParams(Array)
#2 /var/www/arm/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('index', Array)
#3 /var/www/arm/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('v1/users/user-s...', Array)
#4 /var/www/arm/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#5 /var/www/arm/api/web/index.php(15): yii\base\Application->run()
#6 {main}
2018-05-25 18:58:52 [127.0.0.1][1][tsdsfjgmllh43vfb264qimc3fv][info][application] $_GET = [
'args' => ''
]
...
$_SERVER = [
'USER' => 'www-data'
'HOME' => '/var/www'
'HTTP_X_COMPRESS' => 'null'
'HTTP_COOKIE' => 'PHPSESSID=tsdsfjgmllh43vfb264qimc3fv; _csrf=f70915c9bfa9e77535bd94fa3287cb4347f248c120e26332eca5a1cebc7dba4ca%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22mNhgJJk1mrM_luk3c26x-dBOVUY62fpo%22%3B%7D'
'HTTP_ACCEPT_LANGUAGE' => 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7'
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate'
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'
'HTTP_UPGRADE_INSECURE_REQUESTS' => '1'
'HTTP_CACHE_CONTROL' => 'max-age=0'
'HTTP_CONNECTION' => 'keep-alive'
'HTTP_HOST' => 'arm.local'
'REDIRECT_STATUS' => '200'
'SERVER_NAME' => 'arm.local'
'SERVER_PORT' => '80'
'SERVER_ADDR' => '127.0.0.1'
'REMOTE_PORT' => '42354'
'REMOTE_ADDR' => '127.0.0.1'
'SERVER_SOFTWARE' => 'nginx/1.10.3'
'GATEWAY_INTERFACE' => 'CGI/1.1'
'REQUEST_SCHEME' => 'http'
'SERVER_PROTOCOL' => 'HTTP/1.1'
'DOCUMENT_ROOT' => '/var/www/arm'
'DOCUMENT_URI' => '/api/web/index.php'
'REQUEST_URI' => '/api/v1/users/user-settings?key=wagons-array-user-settings'
'SCRIPT_NAME' => '/api/web/index.php'
'CONTENT_LENGTH' => ''
'CONTENT_TYPE' => ''
'REQUEST_METHOD' => 'GET'
'QUERY_STRING' => 'args'
'SCRIPT_FILENAME' => '/var/www/arm/api/web/index.php'
'FCGI_ROLE' => 'RESPONDER'
'PHP_SELF' => '/api/web/index.php'
'REQUEST_TIME_FLOAT' => 1527274732.2266
'REQUEST_TIME' => 1527274732
]
Url manager config:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'/settings' => '/settings',
'/<action>' => '/site/<action>',
'/<controller>' => '/<controller>/<action>',
'/<controller>/<action>' => '/<controller>/<action>',
'/<module>/<action>' => '/<module>/default/<action>',
[
'class' => 'yii\rest\UrlRule',
'controller' => [
# some controllers
'v1/users/user-groups',
'v1/users/user-settings',
],
'pluralize'=>false
],
],
]
section of nginx config
location /api/ {
root /var/www/arm/api/web;
try_files $uri /api/web/index.php?args;
}
Also I see these lines in my nginx log file:
2018/05/25 21:56:21 [error] 27040#27040: *74 FastCGI sent in stderr: "PHP message: PHP Warning: Invalid argument supplied for foreach() in /var/www/arm/vendor/yiisoft/yii2/helpers/BaseArrayHelper.php on line 123" while reading response header from upstream, client: 127.0.0.1, server: arm.local, request: "GET /api/v1/users/user-settings?key=wagons-array-user-settings HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "arm.local"
2018/05/25 21:58:52 [error] 27040#27040: *80 FastCGI sent in stderr: "PHP message: PHP Warning: Invalid argument supplied for foreach() in /var/www/arm/vendor/yiisoft/yii2/helpers/BaseArrayHelper.php on line 123" while reading response header from upstream, client: 127.0.0.1, server: arm.local, request: "GET /api/v1/users/user-settings?key=wagons-array-user-settings HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "arm.local"
Note
It's began after update yii2 to 2.0.15.1 and php 7.2.5.
I try downgrade to php7.2.3, problem still exists.
Production version my app used yii2 v2.0.13 and php 7.2.3 and I haven`t this problem.
If I downgrade yii2 version to 2.0.13 I get this error:
yiisoft/yii2-gii 2.0.7 requires yiisoft/yii2 ~2.0.14 -> satisfiable by yiisoft/yii2[2.0.x-dev]
resp. if I try downgrade yiisoft/yii2-gii to v2.0.0 I get this error:
The requested package yiisoft/yii2-gii (locked at 2.0.7, required as 2.0.0) is satisfiable by yiisoft/yii2-gii[2.0.7]
server nginx + php-fpm
Yii version 2.0.15.1
php version 7.2.5-1
nginx version 1.10
Someone have any ideas?

You have a typo in your nginx configuration, you missed $ before args:
location /api/ {
root /var/www/arm/api/web;
try_files $uri /api/web/index.php?$args;
}

Related

PHP ignores "Content-Type: application/x-www-form-urlencoded"

My executable (C++ compiled with Visual Studio) communicates with the PHP webserver to submit data via POST. It worked as designed for years but suddenly stopped working correctly in January 2023. The only change which may happen is an upgrade of the webserver to PHP-8, and a regular Windows update, which changed WININET.DLL used by executable to send HTTP requests.
I am using the code like this (with my variables appropriately defined):
HINTERNET hSession = InternetOpen( “lpszAgent”, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect( hSession, “server.XXX.com”, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
LPCSTR FAR* rgpszAcceptTypes = { _T("*/*"), NULL };
HINTERNET hRequest = HttpOpenRequest( hConnect, "POST", “path_to_script.php”, NULL, NULL, rgpszAcceptTypes, 0, NULL);
LPCSTR lpszHeaders = "Content-Type: application/x-www-form-urlencoded";
DWORD dwHeadersLength = strlen(lpszHeaders);
LPCSTR pfrmdata = "a=b&etc";//correctly encoded
DWORD dwOptionalLength = strlen(pfrmdata);
bool ok = HttpSendRequest(hRequest, lpszHeaders, dwHeadersLength, (void*)pfrmdata, dwOptionalLength);
Everything works without any errors. However, on the server side, I get an empty POST and the following headers:
SERVER:
array (
'LSPHP_ENABLE_USER_INI' => 'on',
'PATH' => '/usr/local/bin:/usr/bin:/bin',
'TEMP' => '/tmp',
'TMP' => '/tmp',
'TMPDIR' => '/tmp',
'PWD' => '/',
'HTTP_ACCEPT' => '*/*',
'HTTP_CONNECTION' => 'Keep-Alive',
'CONTENT_LENGTH' => '0',
'HTTP_HOST' => ‘Correct ',
'HTTP_USER_AGENT' => 'Correct',
'HTTP_CACHE_CONTROL' => 'no-cache',
'REDIRECT_UNIQUE_ID' => 'Y82i1YUhgzjQfeXqYUTbfQAAAH8',
'REDIRECT_QS_SrvConn' => '70',
'REDIRECT_QS_AllConn' => '75',
'REDIRECT_QS_ConnectionId' => '167442094953986927446367',
'REDIRECT_HTTPS' => 'on',
'REDIRECT_SSL_TLS_SNI' => 'Correct',
'REDIRECT_STATUS' => '200',
'UNIQUE_ID' => 'Y82i1YUhgzjQfeXqYUTbfQAAAH8',
'QS_SrvConn' => '70',
'QS_AllConn' => '75',
'QS_ConnectionId' => '167442094953986927446367',
'HTTPS' => 'on',
'SSL_TLS_SNI' => 'Correct',
'SERVER_SIGNATURE' => '',
'SERVER_SOFTWARE' => 'Apache',
'SERVER_NAME' => 'Correct ',
'SERVER_ADDR' => 'Correct',
'SERVER_PORT' => '443',
'REMOTE_ADDR' => 'Correct',
'DOCUMENT_ROOT' => 'Correct',
'REQUEST_SCHEME' => 'https',
'CONTEXT_PREFIX' => '',
'CONTEXT_DOCUMENT_ROOT' => 'Correct',
'SERVER_ADMIN' => 'Correct',
'SCRIPT_FILENAME' => 'Correct',
'REMOTE_PORT' => '8700',
'REDIRECT_URL' => 'Correct',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'REQUEST_METHOD' => 'GET',
'QUERY_STRING' => '',
'REQUEST_URI' => 'Correct',
'SCRIPT_NAME' => 'Correct',
'PHP_SELF' => 'Correct',
'REQUEST_TIME_FLOAT' => 1674420950.062037944793701171875,
'REQUEST_TIME' => 1674420950,
'argv' =>
array (
),
'argc' => 0,
)
As you may see CONTENT_LENGTH=0 and CONTENT_TYPE is absent at all, while it should be “application/x-www-form-urlencoded”, and REQUEST_METHOD is GET instead of POST.
I understand that CONTENT_TYPE is essential. If it is not there then POST data is not read, REQUEST_METHOD becomes GET, and CONTENT_LENGTH becomes zero and my data submitted consequently ignored by the server.
So, the problem is that CONTENT_TYPE has disappeared from the request. But why? What is wrong now? Please, recall that it used to all work just fine before January 2023.
I tried to downgrade PHP to 7.4 - it did not help.
I put my script on a different server under a site which uses PHP 7.4 - it started working!
I made a new test site on the other server with the latest PHP 8.2 - it does not work.
Downgraded PHP 8.2 to PHP 7.4 - still did not help.
I installed a new test site on other server and set PHP 7.4 during the installation - it now works!
I upgaded it to PHP 8.2 - stopped working.
I downgraded back to PHP 7.4 - still does not work.
Could this have been more confusing? I beg you to give me some ideas. Thank you!
Update:
Thank you so much for all the comments. Indeed, it must be a redirection of HTTP to HTTPS at fault. The hosting provider (Hostmonster) has recently installed free SSL certificates to all the domains and made all domains use HTTPS. They think they have done a great job and refuse to understand my problem. My executable still works via HTTP, and the redirection breaks it. I am failing to explain to them what I need at the level of support I get from them. They think it all works great and advise me to hire a developer :) They do not seem to provide an option to stop redirection.
I think, I should be able to disable their server-wide redirection from the local .htaccess file. But I am not sure how to do that. I guess, I need to see which method they used to enable it, but I could not figure out how to see the Apache configuration for my domain/location on a shared server.
Could you guess which lines in the local .htaccess would possibly disable the automatic redirection from HTTP to HTTPS?

Yii2 redirecting isn't working. Why?

I am newbie in Yii2, and now I build new app manually (using Mark Safronov book).
I tried to redirect my controller to somewhere and it isn't working.
Like this:
return $this->redirect(array('/site/dashboard'));
I think it depends on my settings, do you have any ideas? I'm using niceurls and this is my httaccess file:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
It is my View code
And I had next config: common/config/bootstrap.php
Yii::setAlias('yii2_book', dirname(dirname(__DIR__)) . '/yii2_book');
Code in my controller:
public function actionAdd()
{
$customer = new CustomerRecord();
$phone = new PhoneRecord();
if($customer->load(Yii::$app->request->post()) && $customer->validate() && $phone->load(Yii::$app->request->post())){
$this->store($this->makeCustomer($customer, $phone));
return $this->redirect(['index']);
}
return $this->render('add',compact('customer','phone'));
Stack trace:
2018-01-05 11:30:03 [::1][-][-][error][yii\web\HttpException:400] yii\web\BadRequestHttpException: Unable to verify your data submission. in /Users/sergejandrejkin/PhpstormProjects/yii2_book/vendor/yiisoft/yii2/web/Controller.php:166
Stack trace:
#0 /Users/sergejandrejkin/PhpstormProjects/yii2_book/vendor/yiisoft/yii2/base/Controller.php(155): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
#1 /Users/sergejandrejkin/PhpstormProjects/yii2_book/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('add', Array)
#2 /Users/sergejandrejkin/PhpstormProjects/yii2_book/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('customers/add', Array)
#3 /Users/sergejandrejkin/PhpstormProjects/yii2_book/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#4 /Users/sergejandrejkin/PhpstormProjects/yii2_book/web/index.php(12): yii\base\Application->run()
#5 {main}
2018-01-05 11:30:03 [::1][-][-][info][application] $_POST = [
'_csrf' => 'oUDxUGHONyj8ER3vQc9cvdpMsCJh6DXlPzsnxRCxfu3AArIlA7lYR8tnbN8UuDf_937iFlKnc6tGVhCNQvQKiA=='
'CustomerRecord' => [
'name' => ''
'birth_date' => ''
'notes' => ''
]
'PhoneRecord' => [
'number' => ''
]
]
$_SERVER = [
'REDIRECT_STATUS' => '200'
'HTTP_HOST' => 'localhost:8888'
'HTTP_CONNECTION' => 'keep-alive'
'CONTENT_LENGTH' => '208'
'HTTP_CACHE_CONTROL' => 'max-age=0'
'HTTP_ORIGIN' => 'http://localhost:8888'
'HTTP_UPGRADE_INSECURE_REQUESTS' => '1'
'CONTENT_TYPE' => 'application/x-www-form-urlencoded'
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
'HTTP_REFERER' => 'http://localhost:8888/web/customers/add'
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br'
'HTTP_ACCEPT_LANGUAGE' => 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7'
'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin'
'SERVER_SIGNATURE' => ''
'SERVER_SOFTWARE' => 'Apache/2.2.31 (Unix) mod_wsgi/3.5 Python/2.7.13 PHP/7.0.15 mod_ssl/2.2.31 OpenSSL/1.0.2j DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9 Perl/v5.24.0'
'SERVER_NAME' => 'localhost'
'SERVER_ADDR' => '::1'
'SERVER_PORT' => '8888'
'REMOTE_ADDR' => '::1'
'DOCUMENT_ROOT' => '/Users/sergejandrejkin/PhpstormProjects/yii2_book'
'SERVER_ADMIN' => 'you#example.com'
'SCRIPT_FILENAME' => '/Users/sergejandrejkin/PhpstormProjects/yii2_book/web/index.php'
'REMOTE_PORT' => '49253'
'REDIRECT_URL' => '/web/customers/add'
'GATEWAY_INTERFACE' => 'CGI/1.1'
'SERVER_PROTOCOL' => 'HTTP/1.1'
'REQUEST_METHOD' => 'POST'
'QUERY_STRING' => ''
'REQUEST_URI' => '/web/customers/add'
'SCRIPT_NAME' => '/web/index.php'
'PHP_SELF' => '/web/index.php'
'REQUEST_TIME_FLOAT' => 1515148203.45
'REQUEST_TIME' => 1515148203
'argv' => []
'argc' => 0
]
I've had same issue. Considering store(…) method works fine, try to add Yii::$app->end() after redirect. So
return $this->redirect(['index']);
becomes
$this->redirect(['index']);
Yii::$app->end();
The exception says:
yii\web\BadRequestHttpException: Unable to verify your data submission.
This tell you 2 things:
bad request exception (http code 400): Is a server response that is sent when the request done by the browser is invalid. Checking the exception's stacktrace you can see its thrown in the beforeAction of the actionAdd so your redirect isnt the problem, as the exception is before your code.
Yii usually use this exception when the CSRF check is invalid, so you should check this page
check it out , do you have any echo before that ?
if have just clear it by ob_end_clean();
if any echo or header have exist before redirect , it's wont be work !
try :
flush();
or try
ob_start()
if no one works try javascript method :
echo "<script type='text/javascript'> window.location='http://your complete url .. '; </script>";
that will works 100% ,good luck .
Yes please check your config settings.
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
],
]
Also your mod_rewrite module should be enabled.
Hope it helps!

How to fix ParameterCircularReferenceException?

I have a symfony2 appliciation. We have previously set up a docker-compose stack for development, and this is why we want all its configuration to bet set via environment variables instead of the parameters.yml.
Hence I replaced the content of my parameters.yml from:
parameters:
locale: 'en'
secret: 'SOME_SECURITY_TOKEN'
...
to:
parameters:
locale: '%locale%'
secret: '%secret%'
...
My docker-compose.yml file contains:
my_app:
hostname: my-app
build: .
dockerfile: Dockerfile.dev
ports:
- "9080:80"
- "9043:433"
environment:
LOCALE: en
SECRET: SOME_SECURITY_TOKEN
...
Yet after rebuilding my container I get the exception:
ParameterCircularReferenceException in ParameterBag.php line 209: Circular reference detected for parameter "secret" ("secret" > "secret").
1. in ParameterBag.php line 209
2. at ParameterBag->resolveString('%secret%', array('secret' => true)) in ParameterBag.php line 185
3. at ParameterBag->resolveValue('%secret%', array('secret' => true)) in ParameterBag.php line 214
4. at ParameterBag->resolveString('%secret%', array('secret' => true)) in ParameterBag.php line 185
5. at ParameterBag->resolveValue('%secret%', array()) in ParameterBag.php line 175
6. at ParameterBag->resolveValue(array('secret' => '%secret%', 'router' => array('resource' => '%kernel.root_dir%/config/routing.yml', 'strict_requirements' => null), 'form' => null, 'csrf_protection' =>
null, 'validation' => array('enable_annotations' => true), 'templating' => array('engines' => array('twig')), 'default_locale' => '%locale%', 'trusted_hosts' => null, 'trusted_proxies' => null,
'session' => array('handler_id' => 'api.session.handler.memcached'), 'fragments' => null, 'http_method_override' => true), array()) in ParameterBag.php line 175
7. at ParameterBag->resolveValue(array(array('secret' => '%secret%', 'router' => array('resource' => '%kernel.root_dir%/config/routing.yml', 'strict_requirements' => null), 'form' => null,
'csrf_protection' => null, 'validation' => array('enable_annotations' => true), 'templating' => array('engines' => array('twig')), 'default_locale' => '%locale%', 'trusted_hosts' => null,
'trusted_proxies' => null, 'session' => array('handler_id' => 'api.session.handler.memcached'), 'fragments' => null, 'http_method_override' => true), array('router' =>
array('resource' => '%kernel.root_dir%/config/routing_dev.yml', 'strict_requirements' => true), 'profiler' => array('only_exceptions' => false)))) in MergeExtensionConfigurationPass.php line 45
8. at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in MergeExtensionConfigurationPass.php line 39
9. at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in Compiler.php line 107
10. at Compiler->compile(object(ContainerBuilder)) in ContainerBuilder.php line 589
11. at ContainerBuilder->compile() in bootstrap.php.cache line 2687
12. at Kernel->initializeContainer() in bootstrap.php.cache line 2465
13. at Kernel->boot() in bootstrap.php.cache line 2496
14. at Kernel->handle(object(Request)) in app_dev.php line 30
Yet in my container I do see the env variables:
le-container:/var/www/my-app# env
SECRET=SOME_SECURITY_TOKEN
LOCALE=en
What am I doing wrong and how to fix it?
For some reason, adding a prefix to my environment variable fixed the issue:
parameters:
locale: '%foo_locale%'
secret: '%foo_secret%'
and of course whenever the variable is set as well. My current working theory is that symfony doesn't like having the same parameter name and env variable, yet I am not sure.
parameters:
locale: '%locale%'
secret: '%secret%'
Is useless construction, locale and secret already is parameters. Just remove this block.
There is a solution to use external parameters. Prefix your variables with "SYMFONY__". In your case it would be:
my_app:
...
environment:
SYMFONY__APP__LOCALE: en
SYMFONY__APP__SECRET: SOME_SECURITY_TOKEN
...
And in your parameters you can call it as followed:
parameters:
locale: %app.locale%
secret: %app.secret%

PHP cannot find file for require_once, but it's there?

It's an error in MyBB, after install I get this error from the index:
Warning: require_once(./global.php): failed to open stream: No such file or directory in C:\jws\htdocs\index.php on line 18
Fatal error: require_once(): Failed opening required './global.php' (include_path='.;C:\php\pear') in C:\jws\htdocs\index.php on line 18
Index code near top:
require_once './global.php';
require_once MYBB_ROOT.'inc/functions_forumlist.php';
require_once MYBB_ROOT.'inc/class_parser.php';
The file is there, I checked in the folder. I haven't changed anything in the files. I'm using PHP 5.6.4, and the index file is loaded from a require_once in another file.
Here:
<?php
$_SERVER = array(
"SERVER_PROTOCOL" => "HTTP/1.1","DOCUMENT_ROOT" => "C:/jws/htdocs","REMOTE_ADDR" => "127.0.0.1","REQUEST_URI" => "/","SERVER_SOFTWARE" => "JWS/1.0","argv" => "","REQUEST_TIME" => "Tue, 30 Dec 2014 12:33:14 PST","PHP_SELF" => "/","REMOTE_PORT" => "56601","REQUEST_METHOD" => "GET","SCRIPT_NAME" => "","SERVER_NAME" => "JWS/1.0","PATH_INFO" => "","ORIG_PATH_INFO" => "","argc" => "","GATEWAY_INTERFACE" => "N/I","SERVER_PORT" => "80","SCRIPT_FILENAME" => "C:/jws/htdocs/index.php","HTTP_ACCEPT_LANGUAGE" => "en-US,en;q=0.5","HTTP_HOST" => "127.0.0.1","QUERY_STRING" => "","REQUEST_TIME_FLOAT" => "1419971594194","HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0","HTTP_ACCEPT_ENCODING" => "gzip, deflate","SERVER_ADDR" => "127.0.0.1","HTTP_CONNECTION" => "keep-alive",
);
$_GET = array(
);
$_POST = array(
);
$_COOKIE = array(
);
$_REQUEST = array(
);
require_once 'C:/jws/htdocs/index.php';
?>
replace your index code with this
require_once 'global.php';
require_once MYBB_ROOT.'inc/functions_forumlist.php';
require_once MYBB_ROOT.'inc/class_parser.php';
I managed to use:
chdir("the path");
to change the working directory, and I also had issues with redirection failure in the server.
Thanks for the help!
index.php code near top:
<?PHP
require_once MYBB_ROOT.'/global.php';
require_once MYBB_ROOT.'/inc/functions_forumlist.php';
require_once MYBB_ROOT.'/inc/class_parser.php';
?>
indexTest.php
<?php
define("MYBB_ROOT", __DIR__);
$_SERVER = array(
"SERVER_PROTOCOL" => "HTTP/1.1","DOCUMENT_ROOT" => "C:/jws/htdocs","REMOTE_ADDR" => "127.0.0.1","REQUEST_URI" => "/","SERVER_SOFTWARE" => "JWS/1.0","argv" => "","REQUEST_TIME" => "Tue, 30 Dec 2014 12:33:14 PST","PHP_SELF" => "/","REMOTE_PORT" => "56601","REQUEST_METHOD" => "GET","SCRIPT_NAME" => "","SERVER_NAME" => "JWS/1.0","PATH_INFO" => "","ORIG_PATH_INFO" => "","argc" => "","GATEWAY_INTERFACE" => "N/I","SERVER_PORT" => "80","SCRIPT_FILENAME" => "C:/jws/htdocs/index.php","HTTP_ACCEPT_LANGUAGE" => "en-US,en;q=0.5","HTTP_HOST" => "127.0.0.1","QUERY_STRING" => "","REQUEST_TIME_FLOAT" => "1419971594194","HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0","HTTP_ACCEPT_ENCODING" => "gzip, deflate","SERVER_ADDR" => "127.0.0.1","HTTP_CONNECTION" => "keep-alive",
);
$_GET = array(
);
$_POST = array(
);
$_COOKIE = array(
);
$_REQUEST = array(
);
require_once MYBB_ROOT.'/index.php';
?>

PHP SOAP fatal error message

My webserver has SOAP installed correctly (phpinfo has Soap Client/Server - Enabled).
I'm trying to create a SOAP request to a remote magento store, and I'm getting this error message:
[Mon Aug 29 20:13:59 2011] [error] [client 79.178.13.67] PHP Fatal error: Uncaught SoapFault exception: [0] Unable to load Soap extension on the server in /home/example/public_html/mag/index.php:3
Stack trace:
#0 [internal function]: SoapClient->__call('login', Array)
#1 /home/example/public_html/mag/index.php(3): SoapClient->login('user', 'pass')
#2 {main}\n thrown in /home/example/public_html/mag/index.php on line 3
Code snippet here:
$client = new SoapClient('http://www.example.com/api/soap/?wsdl=1');
$session = $client->login('user','pass');
$attributeSets = $client->call($session,'product_attribute_set.list');
$set = current($attributeSets);
$sku = 'iphone-12345';
$imagePath="../image.jpg";
$newProductData = array(
'name' => 'iPhone',
'websites' => array(1),
'short_description' => 'short description',
'description' => 'description',
'price' => 150,
'status' => '1',
);
$newImage = array(
'file' => array(
'name' => 'file_name',
'content' => base64_encode(file_get_contents($imagePath)),
'mime' => 'image/jpeg'
),
'label' => 'Cool Image',
'position' => 0,
'types' => array('image','small_image','thumbnail'),
'exclude' => 0
);
$imageFilename = $client->call($sessionId, 'product_media.create', array($sku,$newImage));
$productId = $client->call($session,'product.create',array('simple', $set['set_id'],$sku,$newProductData));
echo $productId;
Any ideas?
Thanks,
Try to updating Server side of WSDL (where SoapServer runs)
update :
PHP
PHP-SOAP
and dependencies ;-)
maybe outdated version of php (and/or soap) on server side

Categories