Making hyperlinks execute php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
guycrossley
Forum Newbie
Posts: 9
Joined: Mon May 12, 2003 8:46 pm

Making hyperlinks execute php?

Post 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 :) :)
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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).
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

working

Post by irealms »

i managed to get one working , though i'm using it within a loop, see post

viewtopic.php?t=8995
guycrossley
Forum Newbie
Posts: 9
Joined: Mon May 12, 2003 8:46 pm

Post 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
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

hmmm

Post 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");

?>
ckuipers
Forum Commoner
Posts: 61
Joined: Mon Mar 24, 2003 6:10 am

Post 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.
Post Reply