Jump to content

Input Form


manalnor

Recommended Posts

Hello friends

i need to make the following idea

 

<form method="post">
Enter ID : <input type="text" name="id" />
<input type="submit" value="Submit" />
</form>

 

and the input id should goes to php code on same page as $id

 

$ORGtext= file_get_contents('NewsID=$id');

 

how to write it correct

 

thanks

 

 

Link to comment
Share on other sites

Not very secure?

 

What about?

//at least type cast it!

$id = (isset($_POST['id']) ? (int)$_POST['id'] : 0);

$ORGtext= file_get_contents('NewsID=$id');

 

Well when you submit a form there is a $_POST array generated, and if there is a value in the text box, that will be transmitted into the receiver script, so from there you can grab the ID number and use that to make the file_get_contents("path/to/file".$_POST['ID']."); dynamic  from that sort of arrangement.

 

BUT if you are going to do that, be aware that WHATEVER is sent through the $_POST array, php will interpret as a string, you would need to use either a preg_ function or ctype_digit() or even typecast the incoming var so that you can be certain that it is ONLY a numerical value that is being sent, personally though I would use a preg_ function as ctype_digit is a but lax IMO and your 'safer' using preg because you can be a lot more stricter with the conditional patterns.

 

Hope your not too confused now! I can't write it for you as it would take too much time up, and I couldn't guarantee it being functional as it would be typed OTF, so I would rather advise, not create!

 

Rw   

Link to comment
Share on other sites

BUT if you are going to do that, be aware that WHATEVER is sent through the $_POST array, php will interpret as a string, you would need to use either a preg_ function or ctype_digit() or even typecast the incoming var so that you can be certain that it is ONLY a numerical value that is being sent, personally though I would use a preg_ function as ctype_digit is a but lax IMO and your 'safer' using preg because you can be a lot more stricter with the conditional patterns.

 

Thank you rwwd for the additional explanation. My example shows the need for using $_POST['id'] to set the $id variable (without the php error). To me it is unclear as to the value type of $id as manalnor didn't specify. There are cases were the post value should be a string so no type cast is needed since it will be a string. In either case, it is important to know what type of value you are expecting and validate all *used* $_POST values.

 

Thanks again

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.