Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how do I turn hidden Login form values into session variables?

Explorer ,
May 20, 2009 May 20, 2009

QUESTION: How do I get the hidden form elements for nationality, country, studylang, primelang from the Login form's Post array to become session variables?

Adobe's page at http://kb2.adobe.com/cps/165/tn_16563.html gave me info that didn't work since the code was old. The first question I asked received a useful, but partial answer and none of the values are appearing. The whole thing is laid out below and I don't know if I can make it shorter and still make sense of it.

Page 1 has a login form with six fields.

The textfields in the form are username and password.

The hidden fields in the form are: nationality, country, studylang, primelang and their values will be set by incoming URL paramenters from a prior page or hard coded in.

I am trying to create session variables of the four hidden fields to avoid having to deploy recordsets on every subsequent page.

After the Login button is pushed, I want these four hidden form fields, nationality, country, studylang and primelang, and their values, to pass, as Session Variables,  to the next page and to subsequently be available to all pages so I can use them in links to other pages and in <img src="folderX/SessionVariableValue/book1.php. > Make sense?

Every supporting page seems to work:
On the login page, the $MM_redirectLoginSuccess = "yadayada.php"; works fine.

I've used  <?php if ($_POST) {print_r($_POST);} ?> to check the post array and it is working correctly for all the fields.

I have created the bindings for the four Session Variables with the same words: nationality, country, studylang, primelang and deployed them into the recipient page:

<?php echo $_SESSION['primelang']; ?>

<?php echo $_SESSION['country']; ?>

<?php echo $_SESSION['nationality']; ?>

<?php echo $_SESSION['studylang']; ?>

QUESTION: How do I get the form elements for nationality, country, studylang, primelang from the Post array to input into the head code on the  recipient page? I have this deployed in the head code, but the gentleman who offered to help previously didn't inform me how to get the hidden field values into the 'whatever'.

<?php session_start();
$_SESSION['nationality'] = 'whatever';
$_SESSION['studylang'] = 'whatever';
$_SESSION['primelang'] = 'whatever';
$_SESSION['country'] = 'whatever';

$nationality = $HTTP_POST_VARS['nationality'];
$studylang = $HTTP_POST_VARS['studylang'];
$primelang = $HTTP_POST_VARS['primelang'];
$country = $HTTP_POST_VARS['country'];
?>

What is the magic, missing link?

I tried using Form Variables to pick up the values, but PHP didn't like it or I messed it up.  I cannot find one COMPLETE explanation of how to create, pass, retrieve and deploy Session Variables anywhere on the web. Thank you for your help.

TOPICS
Server side applications
989
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 21, 2009 May 21, 2009

What is the magic, missing link?

You're going to kick yourself, but the magic missing link is the realization that "whatever" is a dummy string that represents whatever you want to assign to the session variable.

<?php session_start();
$_SESSION['nationality'] = $_POST['nationality'];
$_SESSION['studylang'] = $_POST['studylang'];
$_SESSION['primelang'] = $_POST['primelang'];
$_SESSION['country'] = $_POST['country'];
?>

$HTTP_POST_VARS and $HTTP_GET_VARS are obsolete. You should replace them with $_POS

...
Translate
LEGEND ,
May 21, 2009 May 21, 2009

What is the magic, missing link?

You're going to kick yourself, but the magic missing link is the realization that "whatever" is a dummy string that represents whatever you want to assign to the session variable.

<?php session_start();
$_SESSION['nationality'] = $_POST['nationality'];
$_SESSION['studylang'] = $_POST['studylang'];
$_SESSION['primelang'] = $_POST['primelang'];
$_SESSION['country'] = $_POST['country'];
?>

$HTTP_POST_VARS and $HTTP_GET_VARS are obsolete. You should replace them with $_POST and $_GET respectively.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 21, 2009 May 21, 2009

Hi David,

Yes, I had figured that to be the case, but even after making that change, it still isn't putting out the session variables and I can't understand why not.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2009 May 21, 2009

Check that the $_POST variables are being received by the page. $_POST and $_GET variables do not survive beyond one page.

If your login form is self-processing and uses header() to redirect the user to a new page after being authenticated, the $_POST and $_GET variables will be wiped from memory.

Instead of using hidden form fields, you would be better off creating a session on the login page, and creating the session variables there.

<?php

session_start();

if (isset($_POST['primelang'])) {$_SESSION['primelang'] = $_POST['primelang'];}

if (isset($_POST['country'])) {$_SESSION['country'] = $_POST['country'];}

if (isset($_POST['nationality'])) {$_SESSION['nationality'] = $_POST['nationality'];}

if (isset($_POST['studylang'])) {$_SESSION['studylang'] = $_POST['studylang'];}

// login processing script

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 21, 2009 May 21, 2009

yeehaw.gif

do do do do do do dooooo do, do do dit doooooo

(bumbumbumbumbumbum)

Thanks David, that's got it. I'm sure there will be more soon.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2009 May 21, 2009

I assume an ecstatic Snoopy means the question has been answered.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 21, 2009 May 21, 2009
LATEST

Yes it has. My next question, if I can't find good info online, will be about inserting those four Session variable into the mysql db table for the
registration. But I'm reading your book on Registration at the moment and I'll get back to you. Thanks again. I'll close this one out.

Brian

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines