Page 1 of 1

Setting the submit button variable...

Posted: Fri Aug 01, 2003 4:41 pm
by thesilent1
Hey :) , this is probably n00bish but I've got a question: I have a very simple webpage with only a submit button on it. In the code, I have a little PHP script to check if the submit button variable is set. Theoratically, when you go on the page for the first time, the script says that the variable isn't set. When you press the submit button, the page would reload and the script would say that the variable is set because the value of the button would have been passed as a $_POST. Now, in a browser everything works fine. But if you try to give a value to the submit button through a URL the script still says the variable isn't set. Anyway here is the code:

Code: Select all

<html>
<body>
<?php
if(isset($_POST&#1111;'jo'])) &#123;
	echo "hurra!";
	echo $_POST&#1111;'jo'];
&#125; else &#123;
	echo "boo";
	echo $_POST&#1111;'jo'];
&#125;
?>
<form action="index.php" method=POST id=jo>
<input type="submit" name="jo" value="Add News" id="jo">
</body>
</html>
Here is my simple webpage

If you click the button, the page reloads and it displays "hurra!", but if you try accessing the page by writing "http://membres.lycos.fr/xxthesilent1xx/ ... o=whatever" the script says the variable isn't set. Can anyone tell my how to "activate" the variable by typing in a special URL??

Posted: Fri Aug 01, 2003 4:55 pm
by mrskumm
If you want to get variables from the adress typed, then you must use $_GET[]

Posted: Fri Aug 01, 2003 5:12 pm
by thesilent1
hmm, but can't $_POST variables be initialized that way too?

Posted: Fri Aug 01, 2003 5:24 pm
by mrskumm
No... $_POST variables is set when the variables is posted.. Can't explain... But for instance when a script is called from a form with method="post".... $_GET is variables typed after ? in the URL...

but you can do
$_POST['jo']=$_GET['jo'];

and maybe, do some checking
if(isset($_GET['jo'])) {
// jo was typed in URL
} elseif(isset($_POST['jo'])) {
// jo was POST'ed
} else {
// Neither $_GET['jo'] nor $_POST['jo'] was specified
}

Posted: Fri Aug 01, 2003 5:57 pm
by thesilent1
Isn't there a way to initialise POST vars through telnet?

Posted: Fri Aug 01, 2003 7:05 pm
by nielsene
Yes, but it involves rather complicated header-ish type calls. I haven't done it in years.... If you read the HTTP specs you can probably find the necessary calls. Or try using the CURL library.

Posted: Fri Aug 01, 2003 9:15 pm
by Gen-ik
Try this........

Code: Select all

<html> 
<body> 
<?php 
if(isset($jo)) &#123; 
   echo "hurra!"; 
   echo $jo; 
&#125; else &#123; 
   echo "boo"; 
   echo $jo; 
&#125; 
?> 
<form action="index.php" method=POST> 
<input type=hidden name="jo" value="Add News">
<input type="submit" value="Add News"> 
</body> 
</html>

Posted: Fri Aug 01, 2003 9:21 pm
by nielsene
gen-ik suggestion relies upon register_globals being enabled... a false assumption on most hosts for serious security reasons.

Posted: Sat Aug 02, 2003 9:55 am
by thesilent1
I found how to set POST variables through telnet, in this case, the header is:

Code: Select all

POST /xxthesilent1xx/index.php HTTP/1.1
Host: membres.lycos.fr
Content-type: application/x-www-form-urlencoded
Content-length: 11

jo=whatever
:wink:

Posted: Sat Aug 02, 2003 2:27 pm
by sharpasknives

Code: Select all

<html> 
<body> 
<?php 
if (isset($_POST&#1111;'jo'])) &#123;
   $jo = $_POST&#1111;'jo'];
&#125;
if (isset($_GET&#1111;'jo'])) &#123;
   $jo = $_GET&#1111;'jo'];
&#125;
if(isset($jo)) &#123; 
   echo "hurra!"; 
   echo $jo; 
&#125; else &#123; 
   echo "boo"; 
   echo $jo; 
&#125; 
?> 
<form action="index.php" method=POST id=jo> 
<input type="submit" name="jo" value="Add News" id="jo"> 
</body> 
</html>

Re: Setting the submit button variable...

Posted: Sat Aug 02, 2003 3:28 pm
by m3rajk
thesilent1 wrote:Hey :) , this is probably n00bish but I've got a question: I have a very simple webpage with only a submit button on it. In the code, I have a little PHP script to check if the submit button variable is set. Theoratically, when you go on the page for the first time, the script says that the variable isn't set. When you press the submit button, the page would reload and the script would say that the variable is set because the value of the button would have been passed as a $_POST. Now, in a browser everything works fine. But if you try to give a value to the submit button through a URL the script still says the variable isn't set. Anyway here is the code:

Code: Select all

<html>
<body>
<?php
if(isset($_GET&#1111;'jo'])) &#123;
	echo "hurra!";
	echo $_GET&#1111;'jo'];
&#125; else &#123;
	echo "boo";
	echo $_GET&#1111;'jo'];
&#125;
?>
<form action="index.php" method="GET" id=jo>
<input type="submit" name="jo" value="Add News" id="jo">
</body>
</html>
Here is my simple webpage

If you click the button, the page reloads and it displays "hurra!", but if you try accessing the page by writing "http://membres.lycos.fr/xxthesilent1xx/ ... o=whatever" the script says the variable isn't set. Can anyone tell my how to "activate" the variable by typing in a special URL??
the easiest way is what i did to the script.

anything else requires your user to know more about html than most non-hackers do

Posted: Mon Aug 04, 2003 3:40 pm
by thesilent1
Does anyone know the syntax for a PUT http request, what its primarily used for and if its supported by PHP? thx. :)