Read cookies when app starts

Hi,
i have webviewer that is connected with a page that creates 3 cookies when login is correct.
Great, what i want is that when the screen starts (when the app starts) it reads cookies and reading cookies it says to the php pages if the user can login or not.

The problem is that when i login in the php and i generates cookies, then if i exit from the app and i re-entry the cookies seems to be not read by the extension… strange to say. I hope you understand to help me :slight_smile:thanks

Please show your relevant blocks and advise on the extension you are using

Hi Tim.
Extension name is: WEBVIEWCOOKIETOOLS EXTENSION by http://thunkableblocks.blogspot.com/2017/06/webviewcookietools-extension.html

I attach the block…
Thanks

Assuming you have the Home Url set in the designer for the webviewer (?), this could be a timing issue.
Try starting a clock in Screen1.initialise (say 500ms interval), then in the clock timer event stop the clock, then set the label to the GetCookies block.

hi.
No changes :frowning:
have a look as i done… of course the url in the image attached is not the right one (for privacy)

Did you start the clock ? (Clock1.TimerEnabled to true) in Screen1.Initialise ?

also
Try GoToUrl block instead of HomeUrl ?

This works for me in my Companion Emulator

Hi Tim.
I really cannot solve this issue…
I reattach the block.
I explain what happened:
When you open the app you go to index.php page.
On this page the is a check: if cookie is empty it redirects to content.php page.
On content.php the user can click on sign.php and a new cookie will be saved.

Now if i exit the app, when i reopen it the cookie should be read and i don’t have to be redirected to content.php page… but this doesn’t happened.

Otherwise if i clear all cookies and i exit app more then one time, it works: i will be redirected to content.php page…

I attach block img and php file so you can replicate.
Thanks for your patience :slight_smile:

index.txt (165 Bytes) sign.txt (191 Bytes) content.txt (96 Bytes)

thread unlisted

you are using one of the App Inventor distributions, but not App Inventor itself
please ask in the community of the builder you are using

Taifun

1 Like

hi taifun,
it’s the same with mit app inventor.
i can do the project with mit app inv.
can you help me ?
do you need the .aia project to better understand?
sorry but i strongly need a solution for this.
i appreciate your kindly help

each builder is different, therefore ask in the community of the builder you are using

alternatively create your project in App Inventor, check, if the issue still is there, and if yes, provide the relevant App Inventor blocks as screenshot

as you have seen, for @TIMAI2 the example works fine

Taifun

Hello @marco75sa ,

Can you check if this works for you when install the app?

I used this example:
https://www.w3schools.com/php/php_cookies.asp

I think the cookies are getting lost when switching from page to page. Aren’t cookies page specific ?

Cookies.aia (10.8 KB)

<?php
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>
<html>
<body bgcolor="#FF0000">

<?php
if(!isset($_COOKIE[$cookie_name])) {
  echo "Cookie named '" . $cookie_name . "' is not set!";
  
  echo "<br><br><br><br><br> WELCOME!!!! BIENVENIDO A LAS VEGAS!!!!!!
  YOU ARE PRIMERA VEZ HERE.";
} else {
  echo "Cookie '" . $cookie_name . "' is set!<br>";
  echo "Value is: " . $_COOKIE[$cookie_name];
    
	 echo " <br><br><br><br><br> HELLO OLD FRIEND.";

}
?>
  <br><br><br><br><br>

FANTASTIC

</body>
</html>

Hi Juan,
i installed your block codes and added the call of cookie also on the init screen but the result is wrong.
When i try to exit from app and re-entry the loaded cookie is lost…
try by loading more times cookies and clear more times, by exiting from the app…

First is Web component (from Connectivity)

Web1.Url = http://…
WebViewer1.GoToUrl = http://…

i added an exit app button… the cookie is not saved into the app… i have to reload by clicking on the button…
this is not what i want…
i want that the cookie will be read automatically when the app starts. If present on the mobile, when i exit from the app, it must be available also when i re-open the app…
as for chrome or other desktop browser.

The idea is to create a login page via webviewer that read cookies when the app start and if the login is ok then the cookie is saved and available for the future.
Cookies-edited.aia (10.9 KB)

Change Button1 for Screen1.Initialize

doesn’t work…
i open app… i click on get cookies button. I see that tthe cookie is saved.
then i click on exit app so when i reopen the app i should see the cookie saved… .but no: it says that cookie user is not set…

Cookies-edited-2.aia (11.2 KB)