Forum Moderators: coopster

Message Too Old, No Replies

Display form only once per user using sessions

four questions to appear on each page of my web site, but only once

         

s9901470

1:22 pm on Oct 30, 2005 (gmt 0)

10+ Year Member



Hi

I'd like a form with four questions to appear on each page of my web site, but only once per page. At the moment, if someone visits a page twice they get a questionnaire about it again.

Is the a way to use PHP sessions to remember not to display the form if it has already been used?

Any suggestions most welcome.

Thank you in advance,
Ed

henry0

8:51 pm on Oct 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Display your form conditionally.
If it has been used then it fed something
Check if “something is empty or not or modified or not
And use if and else
or even:
if
(isset(S_POST['aaaa']) &&!empty(S_POST['aaaa']) )
or the reverse
(!isset----------- && emty--------- ) )

s9901470

9:51 am on Oct 31, 2005 (gmt 0)

10+ Year Member



Is that the same as using sessions?

henry0

12:24 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes & No, the example does not use sessions
However you may use sessions with the same result
check if session exists and react accordingly.

henry0

12:29 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may also read this post (If you use a DB)

HERE
[webmasterworld.com]

s9901470

9:11 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



I'm not sure how to display a form conditionally based on this, because the page they have just visited might not have been a form page? The form appears on the main page, but they might move around the site and come back to it. If they come back, I don't want it displayed. Does that make sense?

if
(isset(S_POST['aaaa']) &&!empty(S_POST['aaaa']) )

henry0

9:51 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Replace $_POST by $_SESSION

s9901470

9:53 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



I think I want something like this (found it at [mail-archive.com...]

However, I don't need them to register $usr, I just want it to check if a session hasn't been opened, display the form. If it has, don't display it, and carry the session to the next page.

<?php
session_start();

// CHECK IF SESSION EXISTS.
if (!isset($_SESSION['usr'])) {
// IF NO, THEN CHECK FOR COOKIE
if (isset($_COOKIE['usr'])) {
// IF 'YES' THEN START SESSION
$_SESSION['usr'] = $_COOKIE['usr'];
}
// IF 'YES' THEN QUIT }
else {
// IF THE SESSION EXISTS, MAKE SURE [EMAIL PROTECTED] VALUE MATCHES THAT OF THE COOKIE
setcookie("usr", $_SESSION['usr'], mktime(21,00,0,12,31,2014),"/","bigbarn0.kbnet.net", 0);
// END
}

?>

Any help would be most welcome
Thanks