header string problem

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
omerfarooq123
Forum Newbie
Posts: 7
Joined: Thu Jul 09, 2009 3:27 am

header string problem

Post by omerfarooq123 »

i have just created a form to test string function.. i created this func.html
<form method="post" action="func.php" />
<p> <textarea name="text" cols="50" rows="5" wrap="virtual"></textarea>
<br />
<input type="radio" name="func" value="md5" /> MD5 <br />
<input type="radio" name="func" value="strlen" /> String Length <br />
<input type="radio" name="func" value="strrev" /> String Reverse<br />
<input type ="radio" name="func" value="strtoupper" /> String to Upper<br />
<input type="radio" name="func" value="strtolower" /> String to lower<br />
<input type="radio" name="func" value="ucwords" /> First Word to Uper Case<br />
<input type="submit" name="submit" value="Go" />
And then created php file "func.php"
<?
if (($_POST[text] == "") || $_POST[func] == ""))
{
header("Location: func.html");
exit;
}

$result = $_POST[func] ($_POST[text]);
?>

<b>The Result is <b><? echo $result ?>
Every thing is working fine when i remove this function
if (($_POST[text] == "") || $_POST[func] == "")) {
{
header("Location: func.html");
exit;
}
i use this function because if user donot put text or select radio button then header function again bring user to main page..
Help me out why header function is not working even on other scripts i made.. THANKS
Last edited by omerfarooq123 on Fri Dec 25, 2009 7:17 am, edited 1 time in total.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: header string problem

Post by Darhazer »

You have 2 times { and only 1 }, which leads to a parse error
By the way, your code can be used to run any PHP function, including system()
This is a huge security issue.
omerfarooq123
Forum Newbie
Posts: 7
Joined: Thu Jul 09, 2009 3:27 am

Re: header string problem

Post by omerfarooq123 »

well its not working.. can someone help me?? again it give errors
omerfarooq123
Forum Newbie
Posts: 7
Joined: Thu Jul 09, 2009 3:27 am

Re: header string problem

Post by omerfarooq123 »

Darhazer wrote:You have 2 times { and only 1 }, which leads to a parse error
By the way, your code can be used to run any PHP function, including system()
This is a huge security issue.

hey Darhazer thanks for your help.. actually the problem is i use the header function after the html tag which is totally wrong.. i have to use before html tag or no html tag is used on the page.. THANKS Sir
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: header string problem

Post by manohoo »

I notice that most people make this syntax mistake:

incorrect: $_POST[text]

correct: $_POST["text"]
correct: $_POST['text']
Post Reply