Read variable from php page to app

How is the variable x set to true/false on the php page ?

i can set via php or via javascript… this can be done in different way… what i don’t know is how to read the variable…

let’s imagine that in php page i set:
var x = false

blocks (3)

Hmmm, in php you set a variable like this:

$x = false;

Now how are you changing $x to true ?

tim don’t worry about php. Let’s say that the variable of php is x and is set to false, as you wrote.

Now, in mit app, how to read (from php page) x variable?

php page

<?php
$x = "false";
if ( $_GET["whatisx"] == $x ) {
echo $x;
} else {
echo "true";
}
?>

Url

http://localhost:8080/myx.php?whatisx=false

will return false

http://localhost:8080/myx.php?whatisx=true

will return true

ok this is php code. thanks.
what i don’t know how to do is the mit app blocks… how to read the x var from php url to mitapp ?

1 Like

thanks tim , will check your blocks.

tim sorry. maybe we are not understanding… :slight_smile:
I will set x var dynamically inside php with some code.
The app must read the “x” value setted. In your example you set manually the var appending it to the url… and this is not what i want…

i’m searching a way to read variable from app to php page of the webviewer…

You can do what you want with the $x variable in your php page.

As long as you have that $_GET code, you can send the url anytime to get the value of $x. My php was just a simple example

tim you set the x value to the url… i need the reverse… i need to set the x value into the php file and the app must read that value :frowning:

OK, there is probably a better way to do this but:

<?php
$x = "false";
if ( $_GET["getx"] == "" ) {
echo $x;
}
?>

http://localhost:8080/myx.php?getx

will return the value of $x, which is currently “false”

The if/$_GET statement will have to come below any changes made to $x in your other php code, so

<?php
$x = "false";
$x = "true";
if ( $_GET["getx"] == "" ) {
echo $x;
}
?>

would return “true”

tim sorry, maybe i’m let you work too much and i cannot explain my problem.

Starting from the beginning:
i have a webview and 3 buttons: exit, messages, documents (so 3 icon buttons).

In the webview I have three pages: index.php that contains

  1. a link to message.php
  2. a link to documents.php

What i want is that when the webview stays on index.php i can see all 3 buttons but when from the index i go to messages.php then i don’t want to see the “message button”.
So what i imagine is to control visibility of app buttons via true/false variable…

can you pls help me to build this example so i can integrate to my app?

This seems to work

blocks (10)

index.php

<?php
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>Index</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 1.32" />
</head>

<body>
	
	<a href="messages.php">Go to Messages</a>
	<a href="documents.php">Go to Documents</a>
	<script>
	window.AppInventor.setWebViewString("index");
	</script>
</body>

</html>

messages.php

<?php
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>Messages</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 1.32" />
</head>

<body>
	<a href="index.php">Go to Index</a>
	<a href="documents.php">Go to Documents</a>
	<script>
	window.AppInventor.setWebViewString("hideMessages");
	</script>
</body>

</html>

documents.php

<?php
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>Documents</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 1.32" />
</head>

<body>
	<a href="index.php">Go to Index</a>
	<a href="messages.php">Go to Messages</a>
	
	<script>
	window.AppInventor.setWebViewString("hideDocuments");
	</script>
</body>

</html>

@marco75sa

any progress here ?

Sorry meybe i dont know what do you want, but meybe this topic will help you

And this.

1 Like

@Salman_Dev

that is not relevant

yes tim, done. thanks

ooo, im sorry @TIMAI2

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.