Setting the submit button variable...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thesilent1
Forum Newbie
Posts: 5
Joined: Fri Aug 01, 2003 4:41 pm

Setting the submit button variable...

Post 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??
mrskumm
Forum Newbie
Posts: 10
Joined: Tue Jul 22, 2003 5:40 am
Location: Sweden

Post by mrskumm »

If you want to get variables from the adress typed, then you must use $_GET[]
thesilent1
Forum Newbie
Posts: 5
Joined: Fri Aug 01, 2003 4:41 pm

Post by thesilent1 »

hmm, but can't $_POST variables be initialized that way too?
mrskumm
Forum Newbie
Posts: 10
Joined: Tue Jul 22, 2003 5:40 am
Location: Sweden

Post 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
}
thesilent1
Forum Newbie
Posts: 5
Joined: Fri Aug 01, 2003 4:41 pm

Post by thesilent1 »

Isn't there a way to initialise POST vars through telnet?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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>
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

gen-ik suggestion relies upon register_globals being enabled... a false assumption on most hosts for serious security reasons.
thesilent1
Forum Newbie
Posts: 5
Joined: Fri Aug 01, 2003 4:41 pm

Post 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:
sharpasknives
Forum Newbie
Posts: 6
Joined: Sat Aug 02, 2003 7:28 am
Location: Eastbourne, East Sussex, England

Post 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>
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Re: Setting the submit button variable...

Post 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
thesilent1
Forum Newbie
Posts: 5
Joined: Fri Aug 01, 2003 4:41 pm

Post by thesilent1 »

Does anyone know the syntax for a PUT http request, what its primarily used for and if its supported by PHP? thx. :)
Post Reply