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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with a hyperlink to a perl program 1

Status
Not open for further replies.

bucklandripers

Technical User
Joined
Jan 29, 2005
Messages
1
Location
GB
Folks

I think that I have highlighted a problem with using a hyperlink from one perl programme to another.

I am writing software to update records stored on the server.

I have two programs

add_record.pl which receives a request from a display programme to add a new record.

display.pl which

a) receives information from an add_record.pl program

b) updates the records list, and stores them on the server

c) displays the list of records

A request for a new record is initiated in display.pl by the user mousing over a button and clicking. There is a link to add_record.pl via the hyperlink

<!--- New Item --->
<div style="position:absolute; left:20px; top:220px; width:100px; height:20px;">
<a href="/cgi-bin/addto_quality.pl?UserID=$userid"><img src="/newitem.jpg" width="100" height="20" border="0" alt="New Item"></a>
</div>

newitem.jpg is a pretty little button that I cribbed off Frontpage.

So far so good.

I can update the table easily.

The Question arises how to guard against the user pressing the refresh button, sending the data again and updating a copy of the previous record.

I thought a good solution would be to have a refresh switch stored on the server in a text file. When the program add_record.pl was entered, the refresh switch would be set to 1, by opening the text file for writing, printing the new value, then closing the file

open(TXT, ">refresh.txt");
print TXT "1";
close(TXT);

When the data was sent to the display.pl the program display.pl set the switch to -1 before updating the record. A subsequent call to display.pl via the refresh button would find the refresh switch at -1 and no action would be taken, other then to display the records list.

But this idea only partly works. With the simplest of programmes I can flip back and forth between display.pl and add_record.pl. But when I press Refresh Fn5, the program add_record.pl does not set the refresh parameter to 1. It does not seem to open the file.

After many hours trying to understand the problem, I have solved the problem by abandoning the idea of a GET type hyperlink to perl. Instead I created a custom button via

<!--- New Item --->
<div style="position:absolute; left:20px; top:220px; width:100px; height:20px;">
<form method="post" action="/cgi-bin/add_record.pl" >
<input type="hidden" name="UserID" value="$userid" />
<input type = "image" name = "Send2" value="Send2 alt="Send2" src="/newitem.jpg" />
</form>
</div>

where newitem.jpg is the custom button image.

This now works but I dont know why the other method does not. I have used hyperlinks to perl hundreds of times in other contexts with never a problem.

Does this experience ring any bells with other programmers?
It has been driving me crazy!



 
Hi

The simple trick : At the end of add_record.pl output a [tt]Location[/tt] HTTP header to redirect to display.pl. So if the visitor refreshes the page, display.pl will be refreshed.

The complex trick : When displaying the page containing the [tt]form[/tt] generate a random identification number. Add it to the [tt]form[/tt] in a [tt]hidden[/tt] [tt]input[/tt] and save it in the session. When receiving submitted [tt]form[/tt] data, accept it only if the identification number received is the same as the one stored in the session. Then remove the identification number from the session. So if the visitor refreshes the page, the submitted [tt]form[/tt] data will have the same identification number, but the session not, so the data will be rejected.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top