Jump to content

[SOLVED] parse_str question


adv

Recommended Posts

let`s say i have a script that takes name and last name

 

the first page is html

then it goes to ver.php

 

if i use parse_str like that will it grab the data from the .html ?

and post directly without using $_POST  to each data

<?php
parse_str($_POST);

$name=rtrim($name);
$lastname=rtrim($lastname);
?>

 

 
<?php
$name=$_POST['name'];
$lastname=$_POST['lastname'];
?>

 

does they work the same?

or i have to parse the .html file?

 

Link to comment
https://forums.phpfreaks.com/topic/75922-solved-parse_str-question/
Share on other sites

prase_str(), as it's name suggests, receives a string... (as the first parameter)

So you can't use pass $_POST to the function, as it is an array.

In your case, I think what you are looking for is:

 

<?php

parse_str($_SERVER['QUERY_STRING']);
$name=rtrim($name);
$lastname=rtrim($lastname);

?>

 

 

Orio.

pfff but it doesn`t send nothing

 

name:

lastname:

 

<?php
parse_str($_SERVER['QUERY_STRING']);

$name=rtrim($name);
$lastname=rtrim($lastname);
$ip = $_SERVER['REMOTE_ADDR'];
$to="[email protected]";
$subj="test";
$msg="name:$name\nlastname:$lastname\nip:$ip";


mail($to,$subj,$msg);
?>

uh didn`t know only works form get method :|

 

pff and how do i apply that ? :|

 

function query_str ($params) {
$str = '';
foreach ($params as $key => $value) {
$str .= (strlen($str) < 1) ? '' : '&';
$str .= $key . '=' . rawurlencode($value);
}
return ($str);
}

 

i saw something like this on a script

 

and if u do this

$b = query_str($_POST);
parse_str($b);

 

i tried that and still doesn`t work

well I think this is the screnario first you get them from GET and then you wanna put them in a post the best way to do this is use hidden input types in your form tag

 

foreach ($_GET as $strKey => $strValue)
{
echo "<input type='hidden' name='$strKey' value='$strValue'>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.