Jump to content

Archived

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

thminco

passing hidden php variable in html form

Recommended Posts

Can someone please tell me what I am doing wrong here?  For some reason, the variable doess not seem to be getting passed to the "action" php script

 

this input is in my html form (action=post)...

 

 

 

<input type="hidden" name="httpreferer" value="<?php echo $_SERVER['HTTP_REFERER'] ?>" />

 

 

 

 

this is in the action script...

 

$httpreferer=$_POST['httpreferer'];

echo $httpreferer;

Share this post


Link to post
Share on other sites

<input type="hidden" name="httpreferer" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />

 

Was missing a semicolon

Share this post


Link to post
Share on other sites

Did you mean as below? (I tried that)

 

<input type="hidden" name="httpreferer" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />

Share this post


Link to post
Share on other sites

Are you sure $_SERVER['HTTP_REFERER'] is even populated? Can you see nay data in the hidden field when your view source?

Share this post


Link to post
Share on other sites

Try this, it works for me.

 

<html>
<body>

<form action="" method="post">
<input type="hidden" name="httpreferer" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
<input type="submit" />
</form>

</body>
<?php
$httpreferer=$_POST['httpreferer'];
echo $httpreferer;
?>
</html>

Share this post


Link to post
Share on other sites

Make sure the files are saved as .php, and not as .html or another.

Share this post


Link to post
Share on other sites

×

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.