?
Solved

Run PHP function from HREF link?

Posted on 2006-06-06
7
Medium Priority
?
417 Views
Last Modified: 2008-02-01
Hi

I have a page with an <A HREF ...> link on it. When the user clicks that link I want to execute a PHP function (which updates a database table), but I don't want to leave the page I am currently on ... how can I achieve this?

TIA

Martin
0
Comment
Question by:themitch2004
5 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 1000 total points
ID: 16846926
Use target="_blank" to set the link to open a new window, which calls the PHP page in question, or use AJAX, or submit a form on an hidden iframe.
0
 

Author Comment

by:themitch2004
ID: 16847333
Hi Snoyes

I like the idea of the new window, how can I resize the window that is opened from this link? Is this treated as a 'popup' (ie will popup blockers prevent the window opening)? What if the user has javascript disabled?

Thanks again.
Martin
0
 
LVL 17

Assisted Solution

by:BogoJoker
BogoJoker earned 1000 total points
ID: 16847929
a target="_blank" should not be treated as a popup because the user clicked a link, its expected that something should and will happen.  On the other hand if you used window.open() to create a popup then it would most likely be blocked by a popup-blocker.

target="_blank" is not javascript, it is pure html in the <a> tag, so even if the user has javascript turned off it will work.

The thing is you cannot control the size of the window this way as far as I know.  If you do use javascript, you could control the size with a window.open() to make a popup.

Snoyes has some excellent suggestions.

Joe P
0
 
LVL 1

Expert Comment

by:bgcboyus
ID: 16865537
You could just have the link direct them to click.php which records the cilck them do a header redirect to direct them to were you wish them to go or (go back)

click.php

<?

//record the click

header("Location:" .  $_SERVER['HTTP_REFERER']);
?>
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 17027014
Snoyes first post mentions target="_blank".  I just clarified some questions the author had after hearing it from snoyes.  He probably deserves the points.  Or at least a split.

Joe P
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question