Run PHP function from HREF link?

Posted on 2006-06-06
Medium Priority
Last Modified: 2008-02-01

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?


Question by:themitch2004
LVL 33

Accepted Solution

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.

Author Comment

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.
LVL 17

Assisted Solution

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

Expert Comment

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)



//record the click

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

Expert Comment

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

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