Gamma032
Gamma032

Reputation: 451

Sending a Session Variable In a Form

I'm looking to send my session variable: $_SESSION['steamid'] to another webpage by using a form. I also want to have a disabled text form with the variable in it.

Currently, this is the code I have:

$variable = $_SESSION['steamid'];

and

  <input type="hidden" name="b64id" value="'$variable'"/></br>
    <p>Your 64 ID: <input type="text" name="b64id" value="'$variable'" disabled="disabled"/></br>

But I am just recieving "$variable" on the other end. I would like to avoid using POST and Cookies but if it's needed I'm happy to use it. I can ensure that $variable has a value.

Upvotes: 0

Views: 202

Answers (3)

Anri
Anri

Reputation: 1693

when you want to use PHP variable you should open PHP tag

NOT CORRECT

<input type="hidden" name="b64id" value="'$variable'"/></br>
    <p>Your 64 ID: <input type="text" name="b64id" value="'$variable'" disabled="disabled"/></br>

CORRECT

<input type="hidden" name="b64id" value="<?php echo $variable ?>"/></br>
    <p>Your 64 ID: <input type="text" name="b64id" value="<?php echo $variable ?>" disabled="disabled"/></br>

there is a short form <?= $variable ?> it means <?php echo $variable ?>

WELCOME ON PHP WORD !!!

Enjoy :)

Upvotes: 0

Manwal
Manwal

Reputation: 23816

Use following code having php tags:

<input type="hidden" name="b64id" value="<?php echo $variable ?>"/></br>
    <p>Your 64 ID: 
    <input type="text" name="b64id" value="<?php echo $variable ?>" disabled="disabled"/>     
</br>

You should also check if session having value or not. like:

$variable = (isset($_SESSION['steamid']))?$_SESSION['steamid']):'';

Upvotes: -1

John Conde
John Conde

Reputation: 219804

Two issues:

  1. You forgot your PHP tags and echo statement
  2. The single quotes are unnecessary if even if you did #1 would cause the same issue to occur

This should do what you need (assuming PHP 5.4+ or short tags enabled):

 <p>Your 64 ID: <input type="text" name="b64id" value="<?= $variable ?>" disabled="disabled"/></br>

Upvotes: 3

Related Questions