View Full Version : passing hidden data between perl pages.
Hi,
I have one perl generated page that contains about 35 hyperlinks to 35 images. These links take you to a page which shows the specific image.
The variables in my Db are
$dpt_size1img1
$dpt_size2img1.....
......$dpt_size35img1
The lines of code I am trying to send hidden data within read like this:
<form>
<a class="standardlink" href="sourcecode.pl?dpt=chris_dpt">75x75</a>
</form>
Now this link takes me to the correct page but I need more: I need to tell the second page which image I want to display.
Now if the hidden data sent is "$dpt_size1img1" then the perl page (2) should know which Db info to display ie, the file name of the image so that the browser will display the correct image for the specific hyperlink clicked.
Presumably I need to do this through a form tagbut, is one form enough for this whole page or should I use a separate form tag for each hyperlink?
If this isnt clearly explained, I could sent you the whole script.
bazz
MattJakel
07-28-2004, 05:38 PM
You can do it with your link like this:
<a href="sourcecode.pl?dpt=chris_dpt&pic=filelocation">
Or with a form like this:
<script type="text/javascript">
function changepic(picfile) {
document.forms.form.pic.value = picfile
}
</script>
<form action="sourcecode.pl" method="post" name="form">
<input type="hidden" name="dpt" value="chris_dpt">
<input type="hidden" name="pic">
<a href="#" onclick="changepic('filelocation')">75x75</a>
...
</form>
Hope this helps!
Matt
Thanks Matt, I'll try this and see how it goes.
:thumbsup:
Just one more thought though: have I not read somewhere that having a long string like this in the address bar can also enable someone to hack my server more easily?
Bazz
MattJakel
07-29-2004, 07:32 PM
It's true that passing data through a URL makes it easier for people to change things that shouldn't be changed with form data, but that's what the method="post" does. It's supposed to make the data passed invisibly so that they can't change it.
Matt
OK Matt I've tried that but I am not sure that it is what I am looking for.
I have three pieces of data which need to be sent from a hyperlink on one page (whether set up as a form or not), to three separate places on the other page.
(There are 35 hyperlinks on page 1 that need to perform a similar function but with different variables inputted).
For the first hyperlink, the variables are : -
$dpt_name
$dpt_size1img1
$dpt_size1img1 (yes it's to be sent twice but to two different places in the second page).
Now the HTML part of my perl file is written as valid HTML so I can't put perl script in there. Is it possible that I should use the html tags<hidden data> and pass the variables within this?
Bazz
MattJakel
07-30-2004, 11:52 PM
Well if you're going to pass data from a plain HTML page to a script without using the URL to pass the data, you have to use a form. You can combine JavaScript with a form to send the data from hyperlinks, like I showed you previously (that can be changed to edit all of the variables and send them. That's the only way I know of to accomplish what you want to accomplish without sending the data through the URL. Do you want me to edit that code for you so that it will send the right data for each variable?
Matt
Thanks Matt.
I do not want to use JS because it is essential that this works whether viewers have JS turned on or off. It's part of the navigation process in my site. If I am not exposing my site to any increased risk, then I can allow details to be sent thorough the url.
I can't explain what I need without posting the script so far, so I shall post it later. Then if you are willing to help further, I would be delighted.
Bazz
Here is a zip file with the two scripts I have difficulty with. If you want to see the online pages to see how its meant to work, then the first page is here (http://www.thechrissystem.com/cgi-bin/choose_an_image.pl?dpt=chris_dpt) and the the second page is here (http://www.thechrissystem.com?cgi-bin/images_source.pl?dpt=chris_dpt)
OK having re-read my sig, it's time to re ask the question.
In plain html within a perl file, i want to pas two variables form one hyperlink.
The url for the hyperlink in http://www.mydomain.com/cgi-bin/imagessource.pl?dpt=chris_dpt
I want to pass two variables:
variable 1
variable 2
Firstly, how do I do this in the url (ensuring that I have no security holes). I have -t switched on in the perpl script.
secondly, how do I call the passed varibale in the second file. I am thinking that there must be code in the perl and also in the html part.
sorry to have made such a meal of the question at the beginning.
Bazz
MattJakel
08-15-2004, 03:34 AM
So will this work?
In the link:
<a class="standardlink" href="url?dpt=chris_dpt&variable2=value2">75x75</a>
In the script:
#!/usr/bin/perl
use CGI qw(param);
$dpt = param('dpt');
$variable2 = param('variable2');
I didn't really understand your question but I think this is what you're looking for...
Hope this helps,
Matt
Thanks Matt. I'm not surporised you don't understand the question. Its very difficult for me to explain.
I'll try what you have sent and get back to you with the result.
Bazz
OK thats not what I want. and also, whatever version of perl I have it doesnt like that. Is there a 'plug in' that I can add after installing perl? I tried adding a line of code - use Time::gmttime; and it wouldn't accept it.
To explain what I am needing:
on page one there will be twenty thumbnails. when one of them is clicked you are taken to page 2 with a piece of hiddendata specific to that thumbnail. The .pl script in page 2 reads this hiddendata and translates it to a global variable:
hiddendata (image1, image2, image3, image4) = $imagenumber
$picNo = $imagenumber;
then throughout my script I use $picno to insert a specific from the DB. I can't write perl (as you can see) but the wheels of understanding it are slowly starting to turn. Can anyone help with this as my monitor is looking decidedly concerned. :(
Bazz
Ooer :) SUCCESS (ish)
Thanks Matt, I can nojw see where you were coing from with your first answer. I just hadn't got the other snippet in page 2 so that is why it didnt work.
I now link from page one using this url:
mydomain.com/cgi-bin/images_source.pl?dpt=chris_dpt&img=001
in the script of page 2 I then put:
my $imgno = query->param('img');
Thanks for all your help and for reading such an awkward question.
Bazz
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.