Page 1 of 1

Making hyperlinks execute php?

Posted: Thu May 22, 2003 3:11 am
by guycrossley
Hi all!

Is is possible to execute some php when a user clicks on a particular hyperlink?

If i can't use a hyperlink, can a use a button to execute php using the onClick = "" behaviour, and then jump to another URL when it has finished?


--Thx Guys :) :)

Posted: Thu May 22, 2003 3:38 am
by Coco
not 100% sure what your after, but if your wanting to execute on any data then your going to need to send the data in a 'GET' form
ie using urls like: http://www.me.com/mine.php?id=1&mode=monkey

of course the other method would be to actually build a webform and get the user to submit, or to store any data you need in a session or cookie

Posted: Thu May 22, 2003 3:42 am
by volka
as client-side eventhandler you can only register code that the client knows of and that it can execute. None of this applies to php (for almost all browsers).

working

Posted: Thu May 22, 2003 5:01 am
by irealms
i managed to get one working , though i'm using it within a loop, see post

viewtopic.php?t=8995

Posted: Thu May 22, 2003 6:50 am
by guycrossley
What i would like to do is create a very simple hyperlink called "Log Out".

When the user clicks on it it will run some php authentication script (i'm using patUser) to log the user out. Eg...

Code: Select all

<?php
$user->logOff();
?>
Once that is done, the page is linked to index.htm.

I've had a go, but with no success. (I'm really new to all of this guys!)

I appreciate your help :D

--Guy

hmmm

Posted: Thu May 22, 2003 7:02 am
by irealms
might be best to post your authentication script here as well. if we could see how your script works it would be easier.

To make a link execute it however you just need to assign a variable then make an include to cal in the script when the variable is activated.

eg.

Code: Select all

&lt;a href="index.php?logoff=1"&gt;Log off&lt;/a&gt;
then where you want the script to execute in your page use

Code: Select all

<?php
if (logoff=="1") include "logoffscript.php";

?>
then if you want to refresh the page after this and point to index find the area in your script where the actual logout is processed and after that use

Code: Select all

<?php
header("Location: index.php");

?>

Posted: Thu May 22, 2003 8:32 am
by ckuipers
In my opinion, the best thing you can do it to have the hyperlink direct you to a php file that executes the code you want to have executed and in the end of the file execute:

header("Location: index.php");

to redirect you to the page you want to have displayed afterwards.