tags:

views:

42

answers:

4

I've never really thought about this, but it helps with some security of something I'm currently working on. Is it possible to submit GET data without an actual input field, and instead just getting it from the URL?

If so, how would I go about doing this? It kind of makes sense that it should be possible, but at the same time it makes no sense at all.

Perhaps I've been awake too long and need some rest. But I'd like to finish this project a bit more first, so any help you can offer would be appreciated. Thanks

A: 

Yes it's possible. Just append the GET data to the link. For example:

<a href="main.htm?testGet=1&pageNo=54>Test</a>

You can also use Javascript to build the url.

If you happen to be using jQuery and want to build the GET data dynamically you can do this:

var getParams = { testGet:1, pageNo:54 };
$(".myLink").attr("href", url + "?" + $.param(getParams));
CiscoIPPhone
+1  A: 

Is this what you mean?

<a href="/page.php?type=foobar">Link</a>

// page.php

echo $_GET['type']; // foobar
Mike B
+1  A: 

This is what I understand of your question:

  1. You have a <form method="get" action="foo.php">-like tag on your page
  2. You have a series of <input type="text" name="bar"/> in your page
  3. You want to pass additional GET parameters that are not based on an input from the form

If so, it is possible, but I hardly see how it could help with security. Input from a client cannot be trusted, so even if you hardcode the GET value, you have to check it serverside against SQL injection, HTML injection/XSS, and whatnot.

You have two ways:

  1. Use a hidden input: <input type="hidden" name="myHiddenGetValue" value="foobar"/>
  2. Add the GET parameter to the form action: <form method="get" action="foo.php?myHardcodedGetValue=foobar">

If what you meant is that you want to have a GET request without a form, you just need to pass all the GET parameters to the href of a link:

<a href="foo.php?bar=4&baz=5">Click here!</a>
zneak
+1  A: 

Yes. If you add some query-string to yourl url, you can obtain that in php using $_GET without form submitting.

Going to this URL adress http://yoururl/test.php?foo=bar cause echoing foo (if there will be no foo query string, you'll get warning).

# test.php
echo $_GET['foo'] # => bar
retro
You'll get a notice, actually. And only if `error_reporting` is set to display them.
zneak