Sending URL parameters with $this->terminate

Hi all:I’m following something similar to this solution to use a cron.php page.

  1. Used an generated empty PHPMaker page, and put the standalone code in there. Name: cron.php
  2. Gave the cronjob it’s own username/password, i.e. cjmailer
  3. The cronjob accesses login.php via wget (/usr/bin/wget) w un/pw (marked Allow login by URL)
  4. I call my script with "localhost/login?user=my_user&password=my_password&action=importCSV
  5. In Server Events->Other->Login Page->User_LoggedIn I have
function User_LoggedIn($usr)
{
    //Log("User Logged In");
	   $levelid = CurrentUserLevel();
	   switch ($levelid) {  //current user level
		   case 1:  // if JdO
				 $this->terminate("PartesJdoList");
				 break;
                   ....................
		   case 9:  // if CRON
				 $this->terminate("Cron?action=importCSV");
				 break;
		   default:  // timecard users, all others
				 $this->terminate("login");
        }    
}

My problem is my cron can do several task, depending how you call it.
i.e.:
/Cron?action=importCSV
/Cron?action=updateCalendar

The parameter “action” doesn’t arrive to my cron.php page.
I’ve checked the Network tab in Chrome, and I see: login page->index page->cron page.

So, my parameter is lost in index page?
Any idea to workaround it?

Thanks¡¡¡

You may post the code in cron.php file for more discussion.

josejad wrote:

/Cron?action=importCSV
/Cron?action=updateCalendar

Be reminded that the route is not a physical file. If your own standalone file is cron.php, you need to use cron.php?.. If you want to use route (e.g. Cron?..), you need to add a route using the Route_Action server event (see Server Events).

Hi:Thank you both for the answer.

You may post the code in cron.php file for more discussion

Thanks mobhar, here is my code

<?php

namespace PHPMaker2022\semicom;

// Page object
$Cron = &$Page;
?>
<?php

echo "accion = : " & $_GET["accion"];

if (!(isset($_GET["accion"]))) { //si no indicamos ninguna acción, redirigimos a login
  echo "Error";
}
else {
	$db =& DbHelper();
	switch ($_GET["accion"]) {
		case "correo_jdo":
			....

			}
			break;
		case "planificacion":
			...
		break;
		case "importCSV":
			....
			break;
	} //switch
} //else
?>

<?= GetDebugMessage() ?>



Be reminded that the route is not a physical file. If your own standalone file is cron.php, you need to use cron.php?

Thanks arbei.
As you can see, my cron file is generated as a custom file. It can be called with a route. In fact, if I call “Cron?action=importCSV” it works. The problem is the parameter is lost if I call from Login->page_terminate. (see case 9 in my first post).I will try if I can make some test with the Route_Action server event to call it from page_terminate

josejad wrote:

The problem is the parameter is lost if I call from Login->page_terminate

Press F12 in your browser, go to the Network panel, find the request to your custom file, check Headers → Request Headers, see if contains your URL parameter. See View HTTP headers for more information.

Hi again:The network panel show me:

h**ps://partes.test/login?username=cron&password=1234&accion=importCSV
index
Cron

It shows:

Query Strings Parametes
username: cron
password: 1234
accion: importCSV

just for the login lineJust to clarify.

  • If I login typing my cron user and password, and call /Cron?action=importCLV, it works
  • If I login through url (/login?username=cron&password=1234&accion=importCSV) then it goes to index, then /Cron, but no parameters arrive.

Solved adding the code to pageRedirecting in Login:

    public function pageRedirecting(&$url)
    {
        // Example:
        //$url = "your URL";
		   $levelid = CurrentUserLevel();
    	   switch ($levelid) {  //current user level
    		   case -2:  //if Anónimo
    				 $url = "login";
    				 break;
    		   case 1:  // if JdO
					 $url = "PartesJdoList";
    				 //break;
    		   case 2:  // if admon_partes
					 $url = "PartesJdoList";
    				 break;
    		   case 3:  // if Operario
					 $url = "ParteTrabajoList";
    				 break;
    		   case 4:  // if manager
					 $url = "PartesJdoList";
    				 break;				 
    		   case 5:  // if jefe equipo
					 $url = "ParteTrabajoList";
    				 break;		
    		   case 6:  // if Orange
					 $url = "OrangePlaniView2List";
    				 break;	
    		   case 7:  // if PRL
					 $url = "PlanificacionCal";
    				 break;
    		   case 8:  // if Refuerzos
					 $url = "HorasTotalesRefuerzo";
    				 break;	
				case 9:  // if Cron
					$url = "Cron?action=" . $_GET["action"];
					break;				 
    		   default:  // timecard users, all others
    				  $url = "login";
            } 
    }