TYPO3 10.4 session variables - session

how do I implement a session variable like
$GLOBALS['TSFE']->fe_user->setKey('ses','country',$country);
$GLOBALS['TSFE']->storeSessionData();
...
$x = $GLOBALS['TSFE']->fe_user->getKey('ses','country');
in TYPO3 10.4?

Related

Spring boot calling RedisTemplate.execute lua script not concatenating strings

I have a spring boot application and am using redis.
I'm excuting this lua script via the redisTemplate:
local rootKey = tostring(ARGV[1])
local zSetName = tostring(ARGV[2])
local bothStrings = rootKey .. zSetName
return bothStrings
with this in command:
redisTemplate.execute(script, Collections.singletonList("1"),"pointRouteCache", "point");
Only the first value is returned, ie "pointRouteCache".
I expect to see 'pointRouteCachepoint' but I only get 'pointRouteCache', why is that the case?
I'm using spring-boot-starter-parent:2.3.4.RELEASE

How in envoy show debugging info?

Working with envoy in laravel 5.7 I see in examples that echo command is used for debugging purpose.
But whe I write echo in my envoy file, like:
#setup
$server_login_user= 'lardeployer';
$timezone= 'Europe/Kiev';
$path= '/var/www/html/AppDir';
$current = $path . '/current';
$repo= 'git#bitbucket.org:myaccount/votes.git'';
$branch= 'master';
echo "Step # 01";
$writableDirs= [
'/storage/logs',
'/bootstrap/cache'
];
echo "Step # 02";
...
echo "Step # 03";
#endsetup
#servers(['production' => $server_login_user.'#NNN.NN.NN.N])
#task( 'clone', ['on'=>$on] )
...
running envoy script I do not see any echo messages in my console.
I see echo command mentioned in 5.0 version documentation : https://laravel.com/docs/5.0/envoy But that does not
work in my 5.7/5.8 apps. Is echo still supported in laravel ? Or is that some config option ?
Thanks!
if you are going to use echo you should use it inside tasks as mention on laravel too
You may access the options in your tasks via Blade's "echo" syntax.
You may also use if statements and loops within your tasks.
for more detail click here

CodeIgniter Cron Job on Shared Hosting?

I am trying to learn how to do my first cron job using CodeIgniter. In the past, it seemed the only way to do this with CI was to use the wget command instead of php.
The CodeIgniter User Guide, however, says that now you can do this from the command line, for example by running:
$ cd /path/to/project;
$ php index.php controller method
This works great using Terminal on my local setup. But when I use a similar command in the cron section of cPanel on my shared hosting, the task just returns the contents of index.php.
I'm not entirely sure what cPanel does with this command, so unsure as to whether it's using the command line at all.
Could someone explain how I might be able to set up a cron job on shared hosting using CodeIgniter please?
Here is the example code from the CodeIgniter user guide:
tools.php
public function message($to = 'World')
{
echo "Hello {$to}!".PHP_EOL;
}
}
?>
It's going to depend on your host. Cron jobs could really screw stuff up if you're not careful, so a lot of shared hosts don't allow it. You probably need to be on some virtual container (like a VPS, virtuozo, etc.) to do this. This isn't a CodeIgniter issue, but a hosting provider issue. Call them first.
We worked around this exact issue as follows:
Set up a normal php file that is scheduled by cron. Nothing to do with codeigniter yet
Inside it, you can make an fsocket or curl request to perform your regular CodeIgniter call as you do from the web.
Here's an example (say, cron.php)
#!/usr/local/bin/php.cli
<?php
DEFINE('CRON_CALL_URL','https://my_server/'); //
DEFINE('CRON_HTTPS_PORT', 443); // port to use during fsocket connetion
DEFINE('CRON_SSL_PREFIX', 'ssl://'); // prefix to be used on the url when using ssl
$current_time = now();
$md5_hash = md5('somevalue'.$current_time);
$url = CRON_CALL_URL.'MYCTRL/MYMETHOD';
$parts=parse_url($url);
//
$parts['query']='md5_hash='.$md5_hash.'&time='.$current_time;
$fp = fsockopen(CRON_SSL_PREFIX.$parts['host'],
isset($parts['port'])?$parts['port']:CRON_HTTPS_PORT,
$errno, $errstr, 30);
if (!$fp) {
} else {
if (!array_key_exists('query', $parts)) $parts['query'] = null;
$out = "POST ".$parts['path']." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($parts['query'])."\r\n";
$out.= "Connection: Close\r\n\r\n";
if (isset($parts['query'])) $out.= $parts['query'];
fwrite($fp, $out);
fclose($fp);
}
}
?>
NOTE: Make sure that in your MYCTRL/MYMETHOD function you have
ignore_user_abort(true);
that way when you fsocket connection is closed, your script will still run to the end.
We actually have a bunch of these fsockets for various reasons. If you need to make sure that the call to that controller/method came from the cron script, you need to pass some additional hash values so that only cron and the script know it. Once the script is called it has access to any codeigniter functions. Works like a charm.
I've set up 100s of CI cronjob on shared hosting like this: create a short php script which calls the CI controller as if it was a webbrowser.
So, script.php contains this:
script #! /usr/local/bin/php -f /home/example/public_html/script.php
<?php
get_get_contents('http:example.com/cronjob/');
?>
Then set your cronjob in cPanel to call script.php
When it runs Script.php will call the Codeigniter Cronjob controller. There you have the entire CI framework at your disposal.
If you are going to call it like a web browser, why not replace the cronjob
command with:
wget http://example.com/cronjob/
instead of creating something new or simply
curl --suppress http://example.com/cronjob/`

Perl Script to Monitor URL Using proxy credentials?

Please help on the following code, this is not working in our environment.
use LWP;
use strict;
my $url = 'http://google.com';
my $username = 'user';
my $password = 'mypassword';
my $browser = LWP::UserAgent->new('Mozilla');
$browser->credentials("172.18.124.11:80","something.co.in",$username=>$password);
$browser->timeout(10);
my $response=$browser->get($url);
print $response->content;
OUTPUT :
Can't connect to google.com:80 (timeout)
LWP::Protocol::http::Socket: connect: timeout at C:/Perl/lib/LWP/Protocol/http.p m line 51.
OS: windows XP
Regards, Gaurav
Do you have a HTTP proxy at 172.18.124.11? I assume LWP is not using the proxy. You might want to use env_proxy => 1 with the new() call.
You also have a mod-perl2 tag in this question. If this code runs inside mod-perl2, it's possible that the http_proxy env variable is not visible to the code. You can check this eg. by printing $browser->proxy('http').
Or just set the proxy with $browser->proxy('http', '172.18.124.11');
Also, I assume you don't have use warnings on, because new() takes a hash, not just a string. It's a good idea to always enable warnings. That will save you lots of trouble.

How to set date.timezone for CodeIgniter to work with php 5.3

When date.timezone in php.ini is commented out, it gives me:
A PHP Error was encountered
Severity: Warning
Message: main(): It is not safe to
rely on the system's timezone
settings. You are required to use
the date.timezone setting or the
date_default_timezone_set() function.
In case you used any of those methods
and you are still getting this
warning, you most likely misspelled
the timezone identifier. We selected
'America/Los_Angeles' for '-8.0/no
DST' instead
Filename: controllers/helloworld.php
Line Number: 2
When I have
date.timezone = "America/Los_Angeles"
It gives me this:
Server error The website encountered
an error while retrieving
http://localhost/ci/index.php/helloworld.
It may be down for maintenance or
configured incorrectly. Here are some
suggestions: Reload this web page
later. HTTP Error 500 (Internal Server
Error): An unexpected condition was
encountered while the server was
attempting to fulfill the request.
I am using php 5.3, CodeIgniter 2.0.0, and Apache 2.2.
Update 1:
I tried loading a test.php without CodeIgniter, where the first 3 lines of test.php is
date_default_timezone_set('America/Los_Angeles');
echo date("l j \of F Y h:i:s A");
And it works fine, different timezones also works fine too.
So I suspect the problem is from CodeIgniter.
If you Googled "CodeIgniter PHP 5.3" you would have found this article pretty quickly :)
http://philsturgeon.co.uk/blog/2009/12/CodeIgniter-on-PHP-5.3
To fix this, you only need to edit the main index.php for your CodeIgniter application:
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('GMT');
}
This modification is something you will probably need to make for any CodeIgniter application running on PHP 5.3 and can easily be modified to your local timezone. There is a full list of supported timezones in the PHP manual here.
Yes, if you cannot directly edit the php.ini file, placing...
ini_set('date.timezone', 'America/New_York');
...as the first line in CI's index.php works fine.
Reference: PHP's Available Timezones
write in your index.php codeigniter...
/*
|---------------------------------------------------------------
| TimeZone
|---------------------------------------------------------------
|
| default Time Zone
|
*/
if ( function_exists( 'date_default_timezone_set' ) )
date_default_timezone_set('Asia/Jakarta');
Running well in my codeigniter
this is the simple way to do it
$timezone = "Asia/Calcutta";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
//echo date('d-m-Y H:i:s');
$localtime=date('H:i:s');
$sql="INSERT INTO hits (ip,edate,curtime,page_name) VALUES ('$ip', CURDATE(),'$localtime','$filename') ";
date.timezone is intended to go in your php.ini or .htaccess file.
you could do an ini_set('date.timezone', 'America/Los_Angeles'); in the first line of your script and get the desired results.
edit your config.php file
from
$config['time_reference'] = 'local';
to
$config['time_reference'] = 'UTC';

Resources