how can i call function declared in my php file from address bar? I already tried appending function name with site address but it didn't called the function..
http://myWebSite.com/myFile.php?writeMessage
myfile.php:
<?php
/* Defining a PHP Function */
function writeMessage()
{
echo "You are really a nice person, Have a nice time!";
}
/* Calling a PHP Function */
writeMessage();
?>
You can check presence of GET parameter in URL and call function accordingly:
if(isset($_GET['writeMessage'])){
writeMessage();
}
A simple way that i would use given that you dont have too many functions is to use a if statement at the top of the php file and check the parameter of the url.
Lets say url:
http://myWebSite.com/myFile.php?writeMessage
Turn it into:
http://myWebSite.com/myFile.php?function=writeMessage
code:
<?php
$function = $_GET['function'];
if($function == "writeMessage") {
// writeMessage();
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With