How to use Request in Class PHP - php

I'm try to call request from web but not working , this code call command game server from website.
class SampRconAPI
{
private $command;
public function __construct()
{
$this->command = $_REQUEST["command"];
}
if($this->command == "cmdlist")
{
$aCommands = $this->packetSend('cmdlist');
unset($aCommands[0]);
foreach($aCommands as &$sCommand)
{
$sCommand = trim($sCommand);
}
return $aCommands;
}
My Error:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: command
Filename: include/SampRcon.php
Line Number: 7

You can rewrite below line:
$this->command = $_REQUEST["command"];
something like this:
$this->command = isset($_REQUEST["command"]) ? $_REQUEST["command"] : "";
So that it won't give you error.

your error made couldn't found command pram on GET request . first check you service configuration is ok .
<?php
$rcon = new SampRconAPI('server_ip', server_port, 'server_rcon_pass');
$rcon->Call('name ' . $playerid_here);
print_r( $rcon->getInfo());
http://forum.sa-mp.com/showthread.php?t=104299
here is example https://gist.github.com/Westie/234209
?>

Related

ContextErrorException Notice: Undefined index: product in ps_sharebuttons.php line 138

i have this error in my prestashop 1.7 project when i enable mode degub:
ContextErrorException Notice: Undefined index: product in ps_sharebuttons.php line 138.
the line 138 looks like :
$key = 'ps_sharebuttons|' . $params['product']['id_product'];
full code:
public function renderWidget($hookName, array $params)
{
$key = 'ps_sharebuttons|' . $params['product']['id_product'];
if (!empty($params['product']['id_product_attribute'])) {
$key .= '|' . $params['product']['id_product_attribute'];
}
if (!$this->isCached($this->templateFile, $this->getCacheId($key))) {
$this->smarty->assign($this->getWidgetVariables($hookName, $params));
}
please help!
Well this seems an issue with the ps_sharebuttons module, check for an up-to-date version, maybe ?
If you just want get rid of the warning, just modify the code as follow :
public function renderWidget($hookName, array $params)
{
if (isset($params['product'])) {
$key = 'ps_sharebuttons|' . $params['product']['id_product'];
rest of the code here ...
}

How to reference a Class Method using an array variable in PHP7?

I've moved from PHP5 to PHP7.
The following code no longer works.
<?php
class sandbox {
function doit() {
$method = array('name' => 'testresponse');
return $this->$method['name']();
}
function testresponse(){
return "Hi!";
}
}
$h = new sandbox();
echo "Hello, " . $h->doit();
I'm wondering what is the new syntax for this?
Here are the PHP errors I'm getting
A PHP Error was encountered Severity: Notice
Severity: Notice
Message: Array to string conversion
Filename: front/sandbox.php
Line Number: 20
And
Fatal error: Uncaught Error: Function name must be a string in /var/www/application/controller/sandbox.php:20 Stack trace: #0
Change this
return $this->$method['name']();
to this
return $this->{$method['name']}();

php mvc router not working

i have php mvc project .
This is my router class.
router class job is include controller in main index page of website.
its work on localhost but when i uploaded on my host not working
what i do ?
<?php
class route
{
function __construct()
{
if(empty($_GET['url']))
{
$url = "index";
}
else
{
$url = $_GET['url'];
}
$url = explode("/",$url);
if(!empty($url[0]))
{
$controllername = "controllers/".$url[0].".php";
if(file_exists($controllername))
{
require($controllername);
$object = new $url[0];
//$object->loadmodel($url[0]);
if(!empty($url[1]))
{
if(method_exists($object,$url[1]))
{
if(!empty($url[2]))
{
$object->$url[1]($url[2]);
}
else
{
$object->$url[1]();
}
}
else
{
echo "Error";
}
}
else
{
echo "Error";
}
}
else
{
echo "Error";
}
}
}
}
this is my error in error_log
thrown in /home/mogeir/public_html/libs/route.php PHP Notice: Array
to string conversion in /home/mogeir/public_html/libs/route.php on
line 33 PHP Notice: Undefined property: admin::$Array in
/home/mogeir/public_html/libs/route.php on line 33 PHP Fatal error:
Uncaught Error: Function name must be a string in
/home/mogeir/public_html/libs/route.php:33
Use the following function call forms instead - the commented ones are correct alternatives too. See call_user_func and call_user_func_array.
if (!empty($url[2])) {
$object->{$url[1]}($url[2]);
// Alternative 1
// call_user_func(array($object, $url[1]), $url[2]);
// Alternative 2
// call_user_func_array(array($object, $url[1]), array($url[2]));
} else {
$object->{$url[1]}();
// Alternative 1
// call_user_func(array($object, $url[1]));
// Alternative 2
// call_user_func_array(array($object, $url[1]), array());
}
You said:
its work on localhost but when i uploaded on my host not working what i do ?
That has to do with the error reporting activation or with difference in PHP version.

PHP Method, Objects

I have the following PHP code (below) but cannot seem to get it to run? I think I'm missing something simple like a function (?) or other type of code(s)? It should print: My Antonia: Willa Cather (5.99).
Error message:
Fatal error: Call to undefined method shopProduct::getProducer() in C:\Program Files (x86)
<?php
class shopProduct
{
//class body
}
class ShopProductWriter
{
public function write($shopProduct)
{
$str = "{$shopProduct ->title}: " . $shopProduct->getProducer() . " ({$shopProduct -> price})\n";
print $str;
}
}
// we can test it like this
$product1 = new ShopProduct("My Antonia", "Willa", "Cather", 5.99);
$writer = new ShopProductWriter();
$writer->write($product1);
print "Author: {$product1->getProducer()}\n";
?>

Fatal error: Call to undefined function drupal_get_path()

After updating our server to PHP 5.4 and a Drupal site to Drupal 6.37 I keep getting this error message and I am not able to get past it
Fatal error: Call to undefined function drupal_get_path() in /home/mysite/public_html/includes/module.inc on line 285
this is the related function call
function module_load_include($type, $module, $name = NULL) {
if (empty($name)) {
$name = $module;
}
$file = './'. drupal_get_path('module', $module) ."/$name.$type";
if (is_file($file)) {
require_once $file;
}
else {
return FALSE;
}
}
Even when I try to run update.php I still get the same error
I am new to Drupal so any help will be greatly appreciated
Please let me know what additional info you may need since it is my first post here and as I said I don't know much about Drupal

Categories