473,320 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

HREF and PHP code

Tim
I want to execute PHP code when text is clicked (using HREF). I know I
can embed PHP code in the HREF, but that is 'executed' when the screen
is painted, not when the link is clicked.

My objective is to display a list of items, then set a session
variable with the value of the clicked item, before redirecting to
another page.

Is there anyway of doing this or another method ? I want to stick with
PHP and no JavaScripting.
Jul 17 '05 #1
6 3605
The only way I can think of is posting to another (hidden?) frame

Tim wrote:
I want to execute PHP code when text is clicked (using HREF). I know I
can embed PHP code in the HREF, but that is 'executed' when the screen
is painted, not when the link is clicked.

My objective is to display a list of items, then set a session
variable with the value of the clicked item, before redirecting to
another page.

Is there anyway of doing this or another method ? I want to stick with
PHP and no JavaScripting.

Jul 17 '05 #2
.oO(Tim)
I want to execute PHP code when text is clicked (using HREF). I know I
can embed PHP code in the HREF, but that is 'executed' when the screen
is painted, not when the link is clicked.
It's executed before the content is sent to the client. All the client
will get is pure HTML, at this time PHP is long gone.
My objective is to display a list of items, then set a session
variable with the value of the clicked item, before redirecting to
another page.


Call the same page with an URL-parameter with the number of the selected
item, then let PHP insert it into the session and redirect or something
else, e.g.

<ul>
<li><a href="foo.php?item=1">Item 1</li>
<li><a href="foo.php?item=2">Item 2</li>
<li><a href="foo.php?item=3">Item 3</li>
</ul>

HTH
Micha
Jul 17 '05 #3
Tim schrieb:
I want to execute PHP code when text is clicked (using HREF). I know I
can embed PHP code in the HREF, but that is 'executed' when the screen
is painted, not when the link is clicked.
You can't embed PHP code in the HREF!

PHP runs before anything is displayed on the screen. The client will
just get pure HTML.
My objective is to display a list of items, then set a session
variable with the value of the clicked item, before redirecting to
another page.


Why don't you set the session data on the target page?

Regards,
Matthias
Jul 17 '05 #4
The usual way to do this is to have the link go to a PHP script that sets
the session value and automatically redirects the visitor to their
destination. See the documentation on header() for how to do a redirect.

"Tim" <ti*********@mail.com> wrote in message
news:ea**************************@posting.google.c om...
I want to execute PHP code when text is clicked (using HREF). I know I
can embed PHP code in the HREF, but that is 'executed' when the screen
is painted, not when the link is clicked.

My objective is to display a list of items, then set a session
variable with the value of the clicked item, before redirecting to
another page.

Is there anyway of doing this or another method ? I want to stick with
PHP and no JavaScripting.

Jul 17 '05 #5
Tim
Thanks for your help guys, I have written a generic session
setting/redirection script that does the job.

One point though, PHP code can be embeded in an HREF, it is just
'fixed' when the HTML is written.
Jul 17 '05 #6
ti*********@mail.com (Tim) wrote:
Thanks for your help guys, I have written a generic session
setting/redirection script that does the job.

One point though, PHP code can be embeded in an HREF, it is just
'fixed' when the HTML is written.


Right. More accurately, the text that gets sent to the browser never
includes PHP code. By the time the link gets clicked, all traces of PHP
are gone.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Brandon Hoppe | last post by:
I'm trying to change the src of an ilayer in the parent document from a link inside the ilayer. I'm not able to get it to work. All that happens is Netscape 4 crashes. This is for Netscape 4 only....
5
by: Mike | last post by:
In my previous post, I wrote: > ... > GOAL: (very simple) Provide a hyperlink which, when clicked, > calls a javascript function which opens a new URL. > ... > PROBLEM: The following code...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
8
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) {...
2
by: yogesh.bhardwaj | last post by:
Hello all I am trying to modify the link URL when a user clicks on the link. Following is the code: <a onClick="document.location.href=modifyURL(this.href);" href="SOME_DYNAMIC_URL"...
4
by: Jerry Sievers | last post by:
JS Programmers, "I'm a server-side coder PHP, Postgres etc... My question; Given the following anchor <a href="http://www.somesite.com/somefile.html">link text</a> Is there a way to code an...
53
by: usenet | last post by:
See <ul> <li><a name="link1" onClick="alert(this.name);return false;" href="#">Link1</a></li> <li><a name="link2" href="javascript:alert(this);">Link2</a></li> <li>Item 3</li> </ul> ...
14
by: Adnan Siddiqi | last post by:
Hi Suppose I have following URLs comming from an HTML document <a href="http://mydomain1.com">Domain1</a> <a...
12
by: Inny | last post by:
Im trying to rewrite a link with a href function. I need to parse a query string within it ('+tid') But all attempts Have falied. The current onclick/ link function <a href="java...
11
by: coflo | last post by:
Hello I would like to replace an a href link that is provided in the RSS below with my own link. The link that I am looking to replace is defined in the <description> tag within the RSS. Im...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.