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!
I have a PHP file that dynamically creates some HTML links. When one of the links is clicked, I would like to call a PHP function that lives in the same file.
Here is my PHP statement that creates a link:
Just to reiterate, PHP is server-side so all the processing happens on the server not in the user's browser. Unlike Javascript which is client-side (processing done in user's browser effectively), you can't access functions or variables once the page has loaded unless you've used PHP to write them into Javascript.
No. You cannot access a PHP function this way. Look at the source code when the page has loaded, HTML, Javascript but no PHP. When you generate a page you can echo PHP variables into Javascript functions in order to access those variables using Javascript. If you want access to a PHP function you need to go back to the server, ie. refresh the page, post a form...
Mac
Edit:
the php manual wrote:What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server. If you were to have a script ... on your server, the client would receive the results of running that script, with no way of determining what the underlying code may be.
As twigletmac says php is server side and you can't run it client side. This sort of thing sounds like you are trying to log the activity of certain links on your page. A common solution to this problem is to have the link go to a php script rather than directly out to the page intended. You don't have to keep the people on the page you are sending them to just have it run your php script you mention and redirect them to the url you want. You can even pass the url they are to be directed to in the url of the link to the php page you want to run. ie you link to
Thank you all for your responses.
Will I have to access the variable url=www.somesite.com with the $_POST array again when it's sent from one PHP script to another?
No, the $_POST array is essentially for accessing information sent via an HTML form using the POST method. To access information in the query string of the URL you need to use the $_GET array.