Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiperlink with one php call

Status
Not open for further replies.

dominiopt

Technical User
Sep 10, 2001
75
PT
Hi, i need make one hiperlink that when user click goes somewhere and at some time do one php call. It's possible to do ?

<a href="test.htm">test link</a>

The user click must do also one call to test.php file.

Thanks
Fernando
 
I miss this, i did try this code but doesn't work ...

<a href="text.htm"onclick="content.location.href='test.php';">

Thanks for your help
Fernando
 
I told you that you'd have to be a lot more specific than that in the other forum where you posted it.

But, to answer your question the best I understand it, yes it's possible to do go to 2 pages with a page submission, but you have to do it sequentially. One browser window can only handle one page at a time.

Lee
 
Thanks cLFlaVA,

The problem is if i put the php call in the href i got one new page (php) in the browser and after the htm page. Since i only wan't open the htm page the php it's only for email warning i couldn't applie your sugestion.

Fernando
 
What code ? the php one.

When user clicks hyperlink goes to html page, and server sends one mail warning "You have visits", i don't wan't any php page coming on in browser.

<?php
mail("<mail@me.com>","You have visits","","");
?>

Thanks
 
You can't call a PHP script without going to that as a page. You can redirect from that page if there isn't a problem, but you can't link to more than one page at a time. My choice would be to go to the PHP page, check for errors, then if there are none go on to the HTML page you want. If there are, then handle the error and do whatever you do then.

Lee
 
You have a couple of options, ones better than the others. As few have mentioned before me, the easiest option is:

1. initial .html page -> .php page -> final .html page
If that is all your php code, you can use header redirect after that and user will hardly notice they visited .php page.

2. initial .html page -> .php page
You can actually add all your content to the .php page. That way you are down to two pages. Just put that php call at the very top (it will send the mail) and continue outputting the html. Of course, the downside is that mail will be sent every time person reloads or visits that page from another source. You might validate that through referral, though that is not a reliable method.

3. initial .html -> .html page with an invisible (or marginally small) iframe that has the .php page in it.
This would be the closest to what you are looking for though it looks like some kind of virus application -- something goes on in the background you're not aware of. This solution has the same problems as the second, with mail being constantly sent.

All that said, the first option is still recommended.
 
The easiest way to do this is to include an image tag in your page with the href referring to your php program. After your php program sends the email, it outputs a 1x1 pixel invisible gif image. There is some code in the perl forum that you could adapt to do that.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
I am not clear whether you want the form to go to both pages. If you don't then:

<script>
function phpsend() {
location.href='test.php'
return true;
}
</script>

<form name="mail" method="get"
onSubmit="return phpsend()" action="test.htm" target="_blank">

The PHP could have an onload self.close() (maybe)

Otherwise

Clive
 
It's not overly complex at all, it's incredibly simple. All you need in your web page is an image tag that refers to your php program. It takes about 2 lines of code for the php program to return the gif image. You can find perl code I wrote to do that in the perl forum.

This technique has been used for MANY years (over 10 I believe) to allow web pages to gather hit counts and other stats.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top