PHP CLI - rediret to login

Ask the community for help and support.
Post Reply
loop
VIP Member
VIP Member
Posts: 230
Joined: Thu Mar 25, 2021 12:26 pm
Has thanked: 7 times
Been thanked: 3 times

PHP CLI - rediret to login

Post 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,..
Mikepo
Posts: 15
Joined: Mon Oct 26, 2020 12:58 pm
Has thanked: 5 times
Been thanked: 1 time

Re: PHP CLI - rediret to login

Post 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!');
loop
VIP Member
VIP Member
Posts: 230
Joined: Thu Mar 25, 2021 12:26 pm
Has thanked: 7 times
Been thanked: 3 times

Re: PHP CLI - rediret to login

Post by loop »

yeah, would be possible, but i would like to use the script in CLI AND with webbrowsr...any other ideas / solutions?
ecartz
Lead Developer
Lead Developer
Posts: 2656
Joined: Tue Nov 05, 2019 6:02 pm
Has thanked: 4 times
Been thanked: 182 times

Re: PHP CLI - redirect to login

Post 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.
Post Reply