Jump to content

Recommended Posts

Howdy Yall,

 

Ive spent $200 on these damn PHP books and none of em tell me how to run functions. Only how to write the sons of code. Can yall help me in trying to figure out how i can do this. Here is what i wanna do;

 

For Example;

 

function hello()
{
      echo "Hello World";
}

 

That code is in a page called acars.php. Now when the user loads the page acars.php, nothing happens, but when they go to the url in this format. http://mydomain.com/acars.php/hello , Then it will echo Hello World.

 

Let me know what I can do and how I can do it please. Im startin to loose my patience lol. Thanks all.

Link to comment
https://forums.phpfreaks.com/topic/198455-run-function-via-url/
Share on other sites

I know how to run the function via code. But I want the function to code via the URL. So once the user goes to http://mydomain.com/acars.php/hello , It will run the function and display Hello World

 

O i gotcha - first post was a lil unclear

 

You would have the a link like:

<a href="./blah.php?run=hello">Say Hello</a>

 

Then when someone clicks it you need to check the array $_GET for the 'run' array key.

 

if(isset($_GET['run']) && $_GET['run'] == 'hello') {
  hello();
}

 

Read up on how to use $_GET, $_POST and html forms ..etc.

Yeah im aware of it. I really wanted to see if there was a easier way. I did use that way but it was a pain. Thanks,

 

Are you serious?

 

If you want to have "file.php/hello" You'll need to use mod_rewrite which will require the $_GET anyway.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.