Re: Sending a variable without it being seen
| From: | Michael Virnstein | Date: | Wed, 17 Apr 2002 13:11:12 +0000 |
| Subject: | Re: Sending a variable without it being seen | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-93322@lists.php.net to get a copy of this message | ||
variables get passed via URL when you use the GET Method.
You can use POST to do it as you like, but this won't work with
HTML-Links, only with forms.
if you want this feature with html-links, then you can workaround it (will
work in IE, not tested any further):
1. place this code somewhere in your html:
<div id="secretforumlar"></div>
2. place this javascript into your html:
<script language="javascript">
function postHTML(arr_formular)
{
var secform = "<form name=\"" + arr_formular[0] + "\"
method=\"POST\"
action=\"" + arr_formular[1] + "\" target=\"" + arr_formular[2] +
"\">\n";
for( var key in arr_formular)
{
if(key != 0 && key != 1 && key != 2)
{
secform = secform + "<input type=\"hidden\" name=\"" + key +
"\"
value=\"" + arr_formular[key] + "\">";
}
}
secform = secform + "<\/form>";
document.all.secretformular.innerHTML = secform;
var formularname = arr_formular[0];
document.forms[formularname].submit();
}
</script>
this will generate a formular named secretformular in <div
id="secretformular"></div> and submit it via POST
3. now all you have to do is creating a html link like
<a href="javascript:postHTML(arr_formular);">link</a>
arr_formular has to be an array with your form fields.
arr_formular[0]: name attribute of the form
arr_formular[1]: action attribute of the form
arr_formular[2]: target attribute of the form
you can use this php function to generate the link with the expected
variable array "arr_formular":
<?php
function postHTMLLink( $name, $formular= array() )
{?>
<script language="javascript">
foreach( $formular as $key => $value )
{?>
arr_formular['<? echo $key; ?>'] = '<? echo $value; ?>';
<? }?>
</script>
<?
return "<a
href=\"javascript:postHTML(arr_formular)\">".$name."</a>";
}
<?
ex.:
<?php
$array = array (0 => "myform",
1 => "http://www.myworld.com",
2 => "_top",
"testvar1" => 1,
"testvar2" => 2);
echo postHTMLLink("Example", $array);
?>
will generatethe link: <a
href="javascript:postHTMLLink(arr_formular);">Example</a>
Regards Michael
"Kevin Meredith" <kevin@atom.co.za> schrieb im Newsbeitrag
news:PBEOICBNJKIPCKFGEDKGAEHHCKAA.kevin@atom.co.za...
> Hi.
> Is there any way variables can be sent without them being seen?
>
> I am trying to set a session variable from data that is pulled from MySql.
> I have 2 frames open , the first frame has the options available which
when
> selected sends the variable info and opens a page in the second frame.
This
> page then registers the variable showing the selection.
>
> I am currently sending the info like "pagename.php?variable=what
> target=frame"
>
> The links are generated from info in MySql and therefore I have not
managed
> to send the info in a form using hidden fields. The main reason for this
is
> security. Users should not know what variables are being passed or
needed.
>
> Thanks
> Kevin
>