Page 1 of 1

PHP CLI - rediret to login

Posted: Mon Apr 19, 2021 12:41 pm
by loop
Hi Everyone
i need to start specific ADMIN scripts (where i include also the application_top.php) and i found out, that the cli redirects mit alway to login (as i do not have a admin session in the php commandline)
what would be the nicest way to workarround the session check? (of course i could not include the application_top or i could make a if($_GET['php']=="cli" thann don't redirect, but i don't like to change core and i don't like to make security risks)
thank you for any helps,..

Re: PHP CLI - rediret to login

Posted: Mon Apr 19, 2021 1:08 pm
by Mikepo
If you don't need all of application_top just use this:

require('../../includes/configure.php');
require('../../includes/functions/database.php');
echo "<br />active server : " . DB_SERVER . "<br/>active database : " . DB_DATABASE;
tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE) or die('Unable to connect to database server!');

Re: PHP CLI - rediret to login

Posted: Mon Apr 19, 2021 1:09 pm
by loop
yeah, would be possible, but i would like to use the script in CLI AND with webbrowsr...any other ideas / solutions?

Re: PHP CLI - redirect to login

Posted: Mon Apr 19, 2021 5:22 pm
by ecartz
Set up the .htpasswd file authentication. Then call the script https://username:password@example.com/admin/page.php -- obviously replacing username, password, example.com, admin, and page.php with the actual values from your shop.

Alternately create three pages of the script: web.php, cli.php, and include.php. Put all the logic in include.php and include it from both the other scripts. Then use admin/web.php in the browser and use the outside_web_root/cli.php in your CLI script.