5 Replies - 8111 Views - Last Post: 24 June 2011 - 06:28 AM Rate Topic: -----

#1 cs_gal  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 22-October 10

Session variable is empty

Posted 24 June 2011 - 01:12 AM

i have made an email form, there i set a $_SESSION['res'] variable, when the mail is sent. Then i dump this var. After i dump it, i assign it an empty string. In my page all this code lies in a single page. I am getting a string(0) i.e an empty string in var_dump, although the email is being sent. Kindly see what wrong
<?php
session_start();
require_once "mailer.php";

$msg="";

if (!empty($_POST['name1']))
{
$to ="bla@hotmail.com";
$subject = "Form Enquiry" ;

$from="xyz website";
$firstname=$_POST['name1'];
$lastname=$_POST['name2'];
$jobtitle=$_POST['jobtitle'];
$company=$_POST['company'];
$country=$_POST['country'];
$phone=$_POST['cTelNumber'];
$email1=$_POST['cEmail'];

$fromname=$firstname;
$message ="<table width='450' border='1' bgcolor='#FFFFFF' bordercolor='#FFCC00' style='color:#000000; text-align:left'>";
$message .="</tr><tr>"; 
$message .= " <td colspan='2'><strong>Enquiry Details</strong></td>";  
$message .="</tr><tr>";
$message .= " <td>FirstName:</td><td style='text-align:left; width:250px;'>$firstname</td>";
$message .="</tr><tr>";

$message .= "<td>LastName:</td><td style='text-align:left;width:250px;'>$lastname</td>";
$message .="</tr><tr>";
$message .= "<td>Job-Title:</td><td style='text-align:left;width:250px;'>$jobtitle</td>";
$message .="</tr><tr>";
$message .= "<td>Country:</td><td style='text-align:left;width:250px;'>$country</td>";
$message .="</tr><tr>";

$message.= "<td>Company:</td><td style='text-align:left;width:250px;'>$company</td>" ; 
$message .="</tr><tr>";
$message.= "<td>Email:</td><td style='text-align:left;width:250px;'>$email1</td>" ;
$message .="</tr><tr>";
$message.= "<td>Phone:</td><td style='text-align:left;width:250px;'>$phone</td>" ;
$message .="</tr><tr>";
$message.= "</table>" ;

$from="Support@xyz.com";

$MyEmail= new Mailer($to, $fromName, $from, $message, $subject);


if ($MyEmail->send()){

$msg ="Your message has been sent!";
$_SESSION['res']="Your message has been sent!";
 var_dump($_SESSION['res']); 
}
else{
$msg = "Your message could not be submitted, try again later!";
}
header("Location:mapping4.php");
}
?>

<?php var_dump($_SESSION['res']); ?>

//here comes the code for HTML form and the Submit button

<?php  $_SESSION['res']=""; ?>



Is This A Good Question/Topic? 0
  • +

Replies To: Session variable is empty

#2 satis  Icon User is offline

  • D.I.C Head

Reputation: 82
  • View blog
  • Posts: 231
  • Joined: 26-May 11

Re: Session variable is empty

Posted 24 June 2011 - 05:33 AM

Assuming that $MyEmail->send() returns true, I don't see anything wrong with it. I notice you have two var_dumps in there... are they both executing? If only one is, then the send() method may be returning either false or 0. You may want to put an echo in there to verify that part of the code is really executing.

Assuming it does, you may wish to try a simple session test separately to see if sessions are working for you at all:
<?php
session_start();
$_SESSION['test'] = 'yes';
var_dump($_SESSION['test']);
?>


If they're not, check your temp folder settings in php.ini... I know if they're invalid, it can cause sessions to just not work.
Was This Post Helpful? 1
  • +
  • -

#3 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Session variable is empty

Posted 24 June 2011 - 05:33 AM

Line #66 is making your string null. The = operator is for assignments and the == and === operators are for comparisons.

Also your mail script is vulnerable to header injections.
Was This Post Helpful? 0
  • +
  • -

#4 cs_gal  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 22-October 10

Re: Session variable is empty

Posted 24 June 2011 - 06:19 AM

View Postcodeprada, on 24 June 2011 - 05:33 AM, said:

Line #66 is making your string null. The = operator is for assignments and the == and === operators are for comparisons.

Also your mail script is vulnerable to header injections.

I have dumped the session var before assigning it "" in line#66 so it should contain a value

View Postsatis, on 24 June 2011 - 05:33 AM, said:

Assuming that $MyEmail->send() returns true, I don't see anything wrong with it. I notice you have two var_dumps in there... are they both executing? If only one is, then the send() method may be returning either false or 0. You may want to put an echo in there to verify that part of the code is really executing.

Assuming it does, you may wish to try a simple session test separately to see if sessions are working for you at all:
<?php
session_start();
$_SESSION['test'] = 'yes';
var_dump($_SESSION['test']);
?>


If they're not, check your temp folder settings in php.ini... I know if they're invalid, it can cause sessions to just not work.


The session test returns yes... that means session is working. i really can't figure out the problem. now :/
Was This Post Helpful? 0
  • +
  • -

#5 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Session variable is empty

Posted 24 June 2011 - 06:28 AM

Why didn't you assign $_SESSION['res'] to contain the error message also. It should be set in both statements in case your if statement doesn't validate to true which is suppose to initialize $_SESSION['res'].
Your next step is verifying that $MyEmail->send() returns true.
Was This Post Helpful? 0
  • +
  • -

#6 satis  Icon User is offline

  • D.I.C Head

Reputation: 82
  • View blog
  • Posts: 231
  • Joined: 26-May 11

Re: Session variable is empty

Posted 24 June 2011 - 06:28 AM

Are you sure the send() method for the email is returning true? Throw an echo in there, just to be sure.

if ($MyEmail->send()){
	$msg ="Your message has been sent!";
	$_SESSION['res']="Your message has been sent!";
	echo 'Message sent ...session var is ' .$_SESSION['res'] .'<br>';
	var_dump($_SESSION['res']);
}


If you get an echo, but the session is still returning empty... I don't know. Did you turn up PHP error warnings and whatnot? You can throw this in at the top of the script:

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);


Maybe it'll give a clue.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1