calling php function on click of a hyperlink

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
How to call a php function on click of a hyperlink??

Re: calling php function on click of a hyperlink

Quoted text here. Click to load it

Well, php runs at the serverside. So you have to make sure that with the
"click of a hyperlink" the script is requested(activated).

<a href="activate.php?url=foo">http://foo</a>

would result in a resuest of activate.php. So in activate.php you can do
whatever you want, and redirect with header('Location: '.$_GET['url']);

Tim Van Wassenhove <

Re: calling php function on click of a hyperlink

Quoted text here. Click to load it

To clarify....

URL's in the hyperlinks do not reference parts of a php script, such as a
function, or even a line of code.  The script they reference will run in its
entirety, So if your link points to
all of script.php will run.  Once the script is running, you will have to
have conditional sections in your script that are called into action by the
x=yes portion.

The usual ways to control sections executed would include the "if" or
"switch/case" controls.  Using if is pretty straightforward.  If the
condition is met, do this, if not, do something else.  switch is also handy,
and can be good when you have a long string of possiblilities.  Like if you
find yourself needing a constuct like...  if they like blue, do this, if the
like red do this other thing, if they like green do something else, if they
like purple, do something else entirely, everyone else go over here.

I usually build forms that submit their data to themselves, sometimes many
forms in a rows will be all one script.  I control some of these using a
POST variable of "$step" and have conditionals looking for the step number.
If ($_POST[step] == 1) run this section; and so on for step 2 3 4 5 6 and so
on.  Each step is another form submission in a multipart process such as
signing up for a web site.

I probably confused things even further...

Short answer is:

The whole script you send them to with the link will run.  Inside that
script you will need to either have the entire script do one thing or you
will have to build in conditional statements and controls to guide them thru
the script.

Site Timeline