Page 1 of 1
Help with sessions.
Posted: Thu Sep 07, 2006 11:07 pm
by gkwhitworth
Ok...I got the information to the next page using sessions, but I keep on getting errors.
My php code is as follows:
Code: Select all
<?
session_start();
session_register("email");
session_register("name");
session_register("phone");
session_register("contact");
session_register("comments");
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$contact = $_REQUEST['contact'];
$comments = $_REQUEST['comments'];
ini_set("SMTP","127.0.0.1");
mail("contact@gkwinspired.com", "Feedback Form Results" , "name: $name\nPhone: $phone\nContacting Who: $contact\nComments:\n$comments",
"From: $name <$email>");
header ("Location: http://www.gkwinspired.com/feedback.php");
?>
My php on the confirmation page is:
Code: Select all
<?php
session_start();
print("Thank you so much for sending us your feedback.<br><br>");
print("<b>Name:</b> $name<br>");
print("<b>Email:</b> $email<br>");
print("<b>Comments:</b> $comments<br>");
print("<b>Contact Who:</b> $contact<br>");
print("<b>Phone:</b> $phone<br>");
?>
Code: Select all
The errors I am recieving is as follows:
Code: Select all
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\users\gkwinspired.com\feedback.php:12) in D:\users\gkwinspired.com\feedback.php on line 83
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\users\gkwinspired.com\feedback.php:12) in D:\users\gkwinspired.com\feedback.php on line 83
Posted: Fri Sep 08, 2006 12:21 am
by RobertGonzalez
Couple of things wrong with all of that. One, stop using
session_register(). Assign your session vars to the $_SESSION superglobal array. Next, stop treating your sessions vars as though register_globals is on. Next, and most importantly in answering your question, make sure there is nothing at all sent to the browser before your call to
session_start().
As an aside, this problem crops up about once a week. Did you search the forum before posting?
ok...
Posted: Fri Sep 08, 2006 1:17 am
by gkwhitworth
Alright, I really am trying to do this right....
I want to place them all into an array as you said using the $_Session but how would that be accomplished? I just want to have one $_Session so this is what I have so far:
Code: Select all
<?
blah blah
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$contact = $_REQUEST['contact'];
$comments = $_REQUEST['comments'];
$_SESSION["$email && $name && $phone && $contact && $comments"];
?>
I know this isn't correct because I get an error....how would I do this?
--
Greg
P.S. Thanks for the critisism, I am very very new to PHP.
Posted: Fri Sep 08, 2006 1:34 am
by volka
Code: Select all
$_SESSION['email'] = $_REQUEST['email'];
I wouldn't write that for each parameter but use an loop like
Code: Select all
foreach( array('email','name','phone','contact','comments') as $index) {
$_SESSION[$index] = $_REQUEST[$index];
}
Thanks
Posted: Fri Sep 08, 2006 1:45 am
by gkwhitworth
That is exactly what I am looking for....I am not too up with the syntax of PHP yet. I am now getting the following errors from the code though they are:
Code: Select all
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\users\gkwinspired.com\feedback.php:12) in D:\users\gkwinspired.com\feedback.php on line 83
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\users\gkwinspired.com\feedback.php:12) in D:\users\gkwinspired.com\feedback.php on line 83
Here is the sendmail php code:
Code: Select all
<?
session_start();
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$contact = $_REQUEST['contact'];
$comments = $_REQUEST['comments'];
foreach( array('email','name','phone','contact','comments') as $feedback) {
$_SESSION[$feedback] = $_REQUEST[$feedback];
}
ini_set("SMTP","127.0.0.1");
mail("contact@gkwinspired.com", "Feedback Form Results" , "name: $name\nPhone: $phone\nContacting Who: $contact\nComments:\n$comments",
"From: $name <$email>");
header ("Location: http://www.gkwinspired.com/feedback.php");
?>
It seems I constantly have problems with the can't post "blah blah" because I have already sent stuff to the browser...I can't seem to get it down.
Posted: Fri Sep 08, 2006 1:49 am
by volka
Everah wrote:Next, and most importantly in answering your question, make sure there is nothing at all sent to the browser before your call to
session_start().
gkwhitworth wrote:output started at D:\users\gkwinspired.com\feedback.php:12
Something at line 12 generates output. What is line 12?
Posted: Fri Sep 08, 2006 2:01 am
by gkwhitworth
I can't seem to find anything on line 12 on any page, the form page, the php script, or the confirmation page.
Sorry. I tried moving the session_start(); to the top like this:
and I still get errors like this:
Code: Select all
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\users\gkwinspired.com\feedback.php:4) in D:\users\gkwinspired.com\feedback.php on line 5
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\users\gkwinspired.com\feedback.php:4) in D:\users\gkwinspired.com\feedback.php on line 5
Posted: Fri Sep 08, 2006 3:26 am
by jito
just put session start at the top of the page, entire page goes below it like
Code: Select all
<?
//don't put even a space before session start
session_start();
<html>
<head>
//rest of the page
?>
Posted: Fri Sep 08, 2006 7:56 am
by volka
output started at D:\users\gkwinspired.com\feedback.php:4
Now it's line
4.
What is on line 4? It's generating output. php is never ever wrong about that.
Posted: Fri Sep 08, 2006 10:53 am
by RobertGonzalez
This is your problem. You sent the <head> tag to the browser before calling session start. You cannot send anything, not even a single white space, as output before your call to
session_start() (or
header() or
setcookie()) as you will get this error message everytime.
Posted: Fri Sep 08, 2006 5:47 pm
by gkwhitworth
Thanks for all the help guys....I got it to work with no errors and it displays the form information.
--
Greg
Posted: Fri Sep 08, 2006 6:07 pm
by RobertGonzalez
Way to go man. Good job.