This topic is locked
[SOLVED]

Desktop app not redirecting

2/8/2023 3:00:56 PM
PHPRunner General questions
abidcastaneda author

Hello,

I just noticed this:

I have created an application in phprunner wich, redirects the user to the "Add license" screen if he or she have not entered a license number. the redirect works great when I try the application using the web browser, but it doesn't work when tested using it as a desktop app (the desktop app was created using PHPrunner's "Create desktop app" option.

I would love it if anyone can give me any advice on this. And just for consistency, I used redirect the code from the predefined code that phprunner let's you add to the events.
`//********** Redirect to another page ************

header("Location: anypage.php");
exit();`

I did add some of my own, but just to check if a record exists, again, this code works well while using a web browser, but not when used as a phprunner desktop app, could it be the php version used in the generated desktop app?

The full code I'm using in the login page's Before display event is as follows, also, I am including both screen shots, the one from the browser test and the one from the desktop app test:

img alt

img alt

`

//** Check if specific record exists ****

$rs = DB::Query("select * from nothereugmembers where GroupID='1'");
$data=$rs->fetchAssoc();
if($data)
{
// if record exists do something
$pageObject->hideItem("loginform_register_link");
}
else
{
echo "## Solo el primer usuario registrado sera Administrador";
// if dont exist do something else
};

// code from business-template Security for Desktop Apps
$rs = DB::Query("select * from lickemup where activa = 1");
$data=$rs->fetchAssoc();
if($data)
{
// if record exists do something

}
else
{
// if dont exist do something else
//----- CHECK OFLINE LICENSE
$rs = DB::Query("select * from lickemup");
$data=$rs->fetchAssoc();
if($data)
{
// if record exists do something

//--- CHECĶ EXPIRY
$rs = DB::Query("select * from lickemup where expira > date('now') and activa is null");
$data=$rs->fetchAssoc();
if($data)
{
// if record exists do something
$date1=date_create(now());
$date2=date_create($data["expira"]);
$diff=date_diff($date1,$date2);
echo "## La licencia se tiene que activar antes de ".$diff->format("%a dias")."\n";
echo "## Click aqui is le gustaria acivarla: <a href='lickemup_edit.php'>Activar licencia!</a> ";
}
else
{
// if dont exist do something else
echo "## YA EXPIRO";
header("Location: lickemup_edit.php");
exit();
}
//--- CHECĶ EXPIRY
}
else
{
// if dont exist do something else
echo "## NO LICENSE";
header("Location: lickemup_add.php");
exit();

}
//----- CHECK OFLINE LICENSE
}

//** Redirect to another page ****
header("Location: anypage.php");
exit();

// end Security for Desktop Apps code

`

fhumanes 2/10/2023

Hello,

The same happens to me.

I think the line:

header("Location: anypage.php");

You can replace it with:

$html = <<<EOT
<script>
window.open("anypage.php","_self");
</script>
EOT;
echo $html;

Greetings,
fernando

abidcastaneda author 2/10/2023

Hi Fernando!

Thank you very much for the tip, that actually worked, let me explain; today I decided to re - troubleshoot for the nth time and I saw that if I use only this code:
`header("Location: lickemup_add.php");

exit();`

the application works just fine, when I use that inside an if statement is when the trouble starts, it still works if I use this:
`//********** Check offline license ************

$rs = DB::Query("select * from lickemup");
$data=$rs->fetchAssoc();
if($data)
{
// if record exists do something
}
else
{
// if dont exist do something else
//** Add license ****
header("Location: lickemup_add.php");
exit();
//** Add license ****
}
//** Check offline license ****`

But if I add an echo ""; before the page redirect, at the else part of the statement, then it doesn't work, furthermore, if I use the redirect inside an "if else" statement" and add another "if else" before it, it doesn't work either.

I contacted support yesterday but they just kept saying this was a coding issue, I don't know how it is a coding issue, if I use a redirect inside an "if else" statement it should work just fine, but it didn't, that's not bad coding or wrong coding or an error in coding, that just seems to me like there's an error in code handling by the desktop application that's created with phprunner.

And yes, when I changed it and used the code that you suggested inside the "if else" statement it worked like a charm. So again, thank you Fernando, I'll see you around and let me know if there's anything I can help ypu with.

Again, thank you, have an awesome weekend!