Skip to main content
Participating Frequently
September 25, 2009
Question

PHP Sessions not registering

  • September 25, 2009
  • 2 replies
  • 1172 views

I need to register 4 sessions to latter reuse on a conformation page. So far my codes is not saving the sessions, can anyone tell me why? Here is the code on the process script

<?php

//include functions file

include('functions.php');

//Start session

session_start();

//register sessions

session_register('fname');

session_register('lname');

session_register('cell');

session_register('time');

//register all temp names to the form postings

$fname = $_POST['fname'];

$lname = $_POST['lname'];

$cell = $_POST['cell'];

$hr = $_POST['hr'];

$min = $_POST['min'];

$tstamp = $_POST['tstamp'];

//set the value of $temptime to deisplay on the thankyou page

$temptime = "$hr':'$min' '$tstamp";

//Check to make sure all form elements are filled, and that the time stamp is formatted properly. Then set the redirect url.

if($hr == '' or $min == '' or $fname == '' or $lname == '' or cell == '') {

$redirect = 'regfail.html';

}else{

if($tstamp == 'AM') {

if($hr == '1' or $hr == '2' or $hr == '3' or $hr == '4' or $hr == '5' or $hr == '6' or $hr == '7' or $hr == '8' or $hr == '9') {

$time = "0$hr:$min";

}else{

$time = "$hr:$min";

}

}else if($tstamp == 'PM') {

$temphr = $hr + 12;

$time = "$temphr:$min";

}

$redirect = 'thankyou.php';

}

//Register sessions

$_SESSION['fname'] = $fname;

$_SESSION['lname'] = $lname;

$_SESSION['cell'] = $cell;

$_SESSION['time'] = $time;

register($fname, $lname, $cell, $time);

header("Location: $base_dir/$redirect");

exit;

?>

Here is the portion of code that shows the conformation sentence:

Thank you <?php $_SESSION['fname']; ?>

    <?php $_SESSION['lname']; ?>

    for registering with our sms system.

    You will receive your options at <?php $_SESSION['time']; ?>

     at the following number: <?php $_SESSION['cell']; ?>

This topic has been closed for replies.

2 replies

jj12689Author
Participating Frequently
September 26, 2009

I figured out my problem, see bellow what I did.

September 26, 2009

Try your script without the session_register() calls. The PHP manual says that this function is not needed and is deprecated in PHP 5.3:

http://us2.php.net/manual/en/function.session-register.php

You should just be able to use the $_SESSION["variable"] = value syntax.

---
Hieu Bui

Dreamweaver extensions and templates by WebAssist

jj12689Author
Participating Frequently
September 26, 2009

I took out the session register and the script is still not working, any other ideas?

David_Powers
Inspiring
September 26, 2009

The call to session_start() should come at the beginning of the script. You're also using a nonexistent function called register().

Make sure the page that you want to use the session variables on also calls session_start() at the beginning of the page.