Seostats scripts - php

<?php include '../src/class.seostats.php';
try
{
$url = new SEOstats($_GET['url']);
$url->print_array('Google','json');
}
catch (SEOstatsException $e)
{
die($e->getMessage());
}
?>
http://code.google.com/p/seostats/
I want run this but:
$url = new SEOstats($_GET['url']);
is error is for example ['url'] ['mywebpage.com'] or ["mywebpage.com"] error is recurrent in two versions
In first line i have 'home/myuser/public_html/class.seostats.php';
¿Any ideas?

I am the author of the SEOstats package and highly recommend to not use the reference on code.google.com. As stated on the project's start page, you should use the Github pages instead.
My 2nd recommendation is that you should use the dev branch code (which is actually stable - but not yet declared as such): https://github.com/eyecatchup/SEOstats/tree/dev
And finally: Let me get that right: Are you trying to initialize a SEOstats instance as
$url = new SEOstats($_GET['url']['mywebpage.com']); ?
This is at least, what your question suggests. And if that is the case, you should better start here: http://php.net/manual/en/reserved.variables.get.php to understand the example codes of SEOstats.

Related

PHP getenv always returns false

The getenv() always returns false. I am using Symfony dotenv library and loading my variables from a .env file in the root of my project.
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\Dotenv\Exception\PathException;
if (!getenv('APP_ENV')) {
try {
(new Dotenv())->load(__DIR__ . '/../.env');
} catch (PathException $ex) {
echo $ex->getMessage();
exit(1);
}
}
var_dump(getenv('APP_ENV')); // bool(false)
But when I dump the super global I can see my variables
var_dump($_ENV); // array:1["APP_ENV" => "dev"]
So what am I missing?
I m not using symfony but i've encountered the some problem
i am using the vlucas library this is my first code that caused the problem
define('BASE_PATH',realpath(__DIR__.'/../../'));
require_once __DIR__.'/../../vendor/autoload.php';
$dotEnv = Dotenv\Dotenv::createImmutable(BASE_PATH);
$dotEnv->load();
$appName=$_ENV['APP_NAME'];
$appName2=getenv('APP_NAME');
var_dump($appName) // return "This is my website";
var_dump($appName2) // return false;
i didn't knwo the problem at first but it seems that it was because putenv() and getenv()
are not thread safe
so i changed it to this code
define('BASE_PATH',realpath(__DIR__.'/../../'));
require_once __DIR__.'/../../vendor/autoload.php';
$dotEnv = Dotenv\Dotenv::createUnsafeImmutable(BASE_PATH);// <======== :) look here
$dotEnv->load();
$appName=$_ENV['APP_NAME'];
$appName2=getenv('APP_NAME');
var_dump($appName) // return "This is my website";
var_dump($appName2) // return "This is my website";
i hope this resolves your issue
For Symfony 5.x+, in public/index.php
replace
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
with
(new Dotenv())->usePutenv()->bootEnv(dirname(__DIR__).'/.env');
This worked for me.
By default, Symfony doesn't use putenv() (I think it's for security reasons, don't remember exactly) so you are not able to use directly getenv() if you are using Symfony's "fake" environment variables.
The best solution in my opinion is to use dependency injection instead. You can access env vars in your Symfony configuration. For example with a yaml configuration file:
framework:
secret: '%env(APP_SECRET)%'
If you want to be able to use getenv() anyway, that I don't recommand for multiple reasons, you can do this :
Before Symfony 5.1 : In your config/bootstrap.php file -> new Dotenv(true)
Symfony 5.1 and later : public/index.php, add the following before Dotenv instantation-> Dotenv::usePutenv();
EDIT :
Using the putenv PHP function is not thread safe, that's why this setting defaults to false.
Didn't notice in the first place your using the Dotenv component as a standalone library, so you can ignore my advice concerning the dependency injection.
The reason is that using getenv() and putenv() is strongly discouraged due to the fact that these functions are not thread safe, however it is still possible to instruct PHP dotenv to use these functions. Instead of calling Dotenv::createImmutable, one can call Dotenv::createUnsafeImmutable, which will add the PutenvAdapter behind the scenes. Your environment variables will now be available using the getenv method, as well as the super-globals:
$s3_bucket = getenv('S3_BUCKET');
$s3_bucket = $_ENV['S3_BUCKET'];
$s3_bucket = $_SERVER['S3_BUCKET'];

PHP - Get class by included url

I want to getting class by included url between two hosts , I had to called class , there is a point which i have to creating an API , like a library to calling whatever. or it must be do by another way ?!
call.php
<?php
class call{
public function Call_Name($c = "") {
$c = "Called";
return $c;
}
}
?>
index.php
<?php
include 'http://example.com/new/call.php';
$call = new call();
echo $call->Call_Name();
?>
(allow_url_fopen , allow_url_include) is already on.
What you are looking for just isn't safe.
Instead of attempting to execute remote code, consider using a package manager such as Composer/Packagist. You can write your general classes once as a "library" and share them among your "packages".
Take a look here: https://getcomposer.org/ for how to get started.

PHP Reflection class newInstance exit on execution

I'm writing controller testing unit with Fuelphp framework. And inside the code I'm trying to request application controller like this one :
$response = Request::force('controller_name/controller_method')->set_method('GET')->execute();
But this code unexpectedly exits the entire testing unit like PHP exit function. After trying to figure out what happened inside the core source code, I found out that in line 440 of https://github.com/fuel/core/blob/1.9/develop/classes/request.php forces the program to exit without any exception.
$this->controller_instance = $class->newInstance($this);
And before this code
$class = new \ReflectionClass($this->controller)
I'm using PHP 5.6.33 and Fuelphp 1.7.2 in my machine and I hope someone can help me with this error.
I think it's just a typo in your question but to be sure : you said
Request::force
instead of
Request::forge
Anyway, I have a lot of tests wrote in the same way but we add few lines before calling forge it :
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_ACCEPT'] = 'application/json'; // this one may not be required for you
$_POST = array();
$_GET = array();
$request = \Request::forge('controller/action')->set_method('GET');
$request->execute();

Using AdWords BatchJob in PHP

I'm trying to get new BatchJob (https://developers.google.com/adwords/api/docs/guides/batch-jobs) up and running, however missing one part.
Docs says:
The good news is that your client library of choice will have a
utility that handles constructing and sending the request for you. The
example below uses the BatchJobHelper utility from the Java client
library.
However PHP library is missing that Helper and any method that should do that...
Anyone had any luck sending request to API using BatchJob? I can't find any working example anywhere.
Thanks!
In the branch experimental they are rewriting the API. It seems that the BatchJobHelper is missing still (current day of write this), see my issue in github requesting it.
For get BatchJobs you should use the BatchJobService class, which is instantiated from the adword service. This is a example snippet:
$batch_job_service = $adWordsServices->get($session, 'BatchJobService', 'v201605', 'cm');
try
{
/** #var BatchJobReturnValue $result */
$result = $batch_job_service->mutate($operations);
}
catch(ApiException $e)
{
echo $e->getMessage() . PHP_EOL;
}
if(!empty($result) && $result instanceof Google\AdsApi\AdWords\v201605\cm\BatchJobReturnValue)
{
$batch_job = reset($result->getValue());
}
else
{
echo 'Result is empty or no valid';
}
If you are using composer to load the new v201603 version of adwords you will need to also adjust your composer file to map the utils since they are duplicated across the other versions for some reason.. Not sure why they did this. you should be able to find the class you need with the following path. Hope this helps.
{
"require": {
"googleads/googleads-php-lib": "8.3.0"
},
"autoload": {
"classmap": [
"vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/Util/v201601"
]
}
}

Class 'WriteRequestBatch' not found error in Codeigniter - AWS php SDK

Sorry everyone, I'm kind of new to AWS SDK but I need to use WriteRequestBatch to add bulks of 25 records to one table.
I'm using Codeigniter and trying to do it with this code:
function new_save($data_set)
{
$tableName = 'my-table';
$dynamodb = $this->aws_sdk->dynamo_db();
$data_to_save = $this->create_dynamo_data($data_set);
$putBatch = WriteRequestBatch::factory($dynamodb);
foreach ($data_to_save as $record)
{
$record = Item::fromArray($item);
$putBatch->add(new PutRequest($record, $tableName));
}
$putBatch->flush();
}
but it stops with this error:
PHP Fatal error: Class 'WriteRequestBatch' not found in (...)
I've just started to use new SDK and I am able to get data and update table throughput settings etc, only this task fails on me totally :-(
BTW - this is my first post here, and I tried to search on Google etc for answers but found only the same sample code I use already.
I created a library like this:
require('/var/www/xx-aslan/aws_sdk_ver2/aws-autoloader.php');
use Aws\Common\Aws;
class Aws_sdk
{
// Create a service locator using a configuration file
private static $aws = array(
'key' => '***********',
'secret' => '******',
'region' => '****'
);
function aws()
{
return Aws::factory(self::$aws);
}
function dynamo_db()
{
$aws = $this->aws();
return $aws->get('DynamoDb');
}
and I am loading it in the model where the function new_save() is:
$this->load->library('aws_sdk');
Anyone could help me out here?
I know it's probably some really newbie question, sorry :-(
Thanks in advance!
Kasia
If it does not work to change:
$this->load->library('aws_sdk');
to
$this->load->library('Aws_sdk');
as I suggested in the comments, try calling it like:
$putBatch = aws_sdk->WriteRequestBatch::factory($dynamodb);
You would do this every time you use your aws_sdk library.
Hope this helps.
This is not a problem with the AWS SDK or with CI. The classes are namespaced, so you must import them to make them available.
In the same file that you are referencing them, add use statements at/near the top of the file (outside of any class or function declarations).
<?php
// ...
use Aws\DynamoDb\Model\BatchRequest\PutRequest;
use Aws\DynamoDb\Model\BatchRequest\WriteRequestBatch;
use Aws\DynamoDb\Model\Item;
// ...
function new_save($data_set)
{
// ...
$putBatch = WriteRequestBatch::factory($dynamodb);
// ...
}
// ...
You should consider giving the namespaces section in the PHP manual a read if you want to get a better understanding of how to work with namespaced code.

Categories