form question

D

Doug

How can a form with a hidden <input type be triggered without the submit
button type or other button? I am calling a download file href and want it
to access a PHP GET or POST on top of the same page of code. This is the
code so far:

<?
if(isset(_POST['ver']) {
// access and query the database
} ?>
....
<td><form action="<?_$_SERVER['PHP_SELF']?>" method="post">
<a href="./Download Files/somefile.exe">somefile</a>
HOW TO TRIGGER AND name = 'ver'
</form></td>
 
T

Tina - AxisHOST, Inc.

Doug said:
How can a form with a hidden <input type be triggered without the submit
button type or other button? I am calling a download file href and want
it
to access a PHP GET or POST on top of the same page of code. This is the
code so far:

You want to do that without the visitors knowledge/permission??

--Tina
 
D

Doug

Tina - AxisHOST said:
You want to do that without the visitors knowledge/permission??

--Tina

Yes, the only data is an autoinc, NOW() time, and the name of the download.
I would like to track how many and frequency the downloads are occurring.
 
T

Toby Inkster

Doug said:
How can a form with a hidden <input type be triggered without the submit
button type or other button? I am calling a download file href and want it
to access a PHP GET or POST on top of the same page of code.

<!-- this is your HTML page -->
<a href="download.php?ver=2&amp;file=somefile.exe">somefile</a>


<?php
// This is download.php
if (isset($_GET['ver']))
{
// do stuff
}
$redirect = "http://www.example.org/downloads/{$_GET['file']}";
header("Location: $redirect");
?>
 
D

Doug

Toby Inkster said:
<!-- this is your HTML page -->
<a href="download.php?ver=2&amp;file=somefile.exe">somefile</a>

Is download.php the name of the web page it is on? ver is the string
'somefile'. What is the coding ver=2&amp mean?

I almost see the reasoning, Thanks, Doug Eilertson
<?php
// This is download.php
if (isset($_GET['ver']))
{
// do stuff
}
$redirect = "http://www.example.org/downloads/{$_GET['file']}";
header("Location: $redirect");
?>
 
T

Toby Inkster

Doug said:
What is the coding ver=2&amp mean?

The URL is "download.php?ver=2&file=somefile.exe". However, HTML has
certain "special characters" which must be "escaped".

For example, if you're writing some maths and need to use the "less than"
sign, you shouldn't just use "<", because browsers might interpret it as
the start of a tag, so you use "&lt;" (this type of code is called an
"entity reference".

Similarly, when you want to use an "&" as part of normal text, or part
of a URL, you can't use "&", because browsers might interpret it as the
start of an entity reference. So you need to write it as "&amp;" instead.

So the URL "download.php?ver=2&file=somefile.exe" is linked to like this:

<a href="download.php?ver=2&amp;file=somefile.exe">
 
D

Doug

Thanks!

Toby Inkster said:
The URL is "download.php?ver=2&file=somefile.exe". However, HTML has
certain "special characters" which must be "escaped".

For example, if you're writing some maths and need to use the "less than"
sign, you shouldn't just use "<", because browsers might interpret it as
the start of a tag, so you use "&lt;" (this type of code is called an
"entity reference".

Similarly, when you want to use an "&" as part of normal text, or part
of a URL, you can't use "&", because browsers might interpret it as the
start of an entity reference. So you need to write it as "&amp;" instead.

So the URL "download.php?ver=2&file=somefile.exe" is linked to like this:

<a href="download.php?ver=2&amp;file=somefile.exe">
 
D

Doug

Toby Inkster said:
The URL is "download.php?ver=2&file=somefile.exe". However, HTML has
certain "special characters" which must be "escaped".

For example, if you're writing some maths and need to use the "less than"
sign, you shouldn't just use "<", because browsers might interpret it as
the start of a tag, so you use "&lt;" (this type of code is called an
"entity reference".

Similarly, when you want to use an "&" as part of normal text, or part
of a URL, you can't use "&", because browsers might interpret it as the
start of an entity reference. So you need to write it as "&amp;" instead.

So the URL "download.php?ver=2&file=somefile.exe" is linked to like this:

<a href="download.php?ver=2&amp;file=somefile.exe">
It works alright for the download, but how can I pass the 'name' of the
version string of the html? This is what I have so far:

if (isset($_GET['ver']))
{
$vers = "./download.php/{$_GET['name']}";
require_once('./MyStuff/mysql_connect.php');
$query2 = "INSERT INTO versiondl(Version, Date)
VALUES('$ver', NOW())";
$redirect = "./Download Files/{$_GET['file']}";
header("Location: $redirect");
}
?>
 
T

Toby Inkster

Doug said:
$vers = "./download.php/{$_GET['name']}";

What is this?! Where did you get $_GET['name'] from?

$ver = $_GET['ver'];
require_once('./MyStuff/mysql_connect.php');
$query2 = "INSERT INTO versiondl(Version, Date)
VALUES('$ver', NOW())";
mysql_query($query2);
 
D

Doug

I really thank you for the insight into this. The following is what I ended
up with that works great:

<!-- HTML page -->
<a href="download.php?ver=2&amp; file=somefile.exe?ver=2&amp;
name=somefile">somefile</a>

<?php
// This is download.php
if (isset($_GET['ver']))
{
$vers = "{$_GET['name']}";
require_once('./MyStuff/mysql_connect.php');
$query2 = "INSERT INTO versiondl(Version, Date)
VALUES('$vers', NOW())";
$result = @mysql_query ($query2); // Run the query.
$redirect = "./Download Files/{$_GET['file']}";
header("Location: $redirect");
}
?>
 
T

Toby Inkster

Doug said:
<!-- HTML page -->
<a href="download.php?ver=2&amp; file=somefile.exe?ver=2&amp;
name=somefile">somefile</a>

<?php
// This is download.php
if (isset($_GET['ver']))
{
$vers = "{$_GET['name']}";
require_once('./MyStuff/mysql_connect.php');
$query2 = "INSERT INTO versiondl(Version, Date)
VALUES('$vers', NOW())";
$result = @mysql_query ($query2); // Run the query.
$redirect = "./Download Files/{$_GET['file']}";
header("Location: $redirect");
}
?>

OK -- you should be able to cut that down and make it more efficient:

<!-- HTML page -->
<a href="download.php?file=somefile.exe&amp;name=somefile">somefile</a>

<?php
// This is download.php
if (isset($_GET['name']))
{
require_once('./MyStuff/mysql_connect.php');
$query2 = sprintf("INSERT INTO versiondl(Version, Date)
VALUES('%s', NOW())", $_GET['name']);
$result = @mysql_query ($query2); // Run the query.
$redirect = "./Download Files/{$_GET['file']}";
header("Location: $redirect");
}
?>

That said, when you use a "Location" header, you should use a full,
absolute URL, including the "http://".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top