Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP Sessions - HELP

So, I apologize for the terrible title, but I'll try to explain it the best I can.

I have a contact form, and once you click a link, it forwards you to our homepage.
I want this to appear at the top of the page

PHP Code

<?php 
<!DOCTYPE html>
<
html>
<
head>
<
script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<
script> 
$(
document).ready(function(){
  $(
"#flip").click(function(){
    $(
"#panel").slideToggle("slow");
  });
});
</
script>

<
style> 
#panel,#flip
{
padding:5px;
text-align:center;
background-color:#00BFFF;
border:solid 1px #c3c3c3;
}
#panel
{
padding:15px;
display:none;
}
</
style>
</
head>
<
body>

<
div id="flip">Success!</div>
<
div id="panel">Your form has been submitted. <b>If</b> your form required being contacted, you will be contacted ASAP.</div>

</
body>
</
html> 

How can I make this appear only when you come from certain pages or under some condition?

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
Short and simple solution is to simply store a value in the session variable.
So in the first page:
PHP Code

<?php 
$_SESSION
["success"] = true;  // or any value really 

And on the second page:
PHP Code

<?php 
if (isset($_SESSION["success"])) {
    
// echo what you want
    
unset($_SESSION["success"]); // So the message doesn't always show up
} 

Hope this helped!
(Dec 15, 2014 09:44 PM)const Wrote:  Short and simple solution is to simply store a value in the session variable.
So in the first page:
PHP Code

<?php 
$_SESSION
["success"] = true;  // or any value really 

And on the second page:
PHP Code

<?php 
if (isset($_SESSION["success"])) {
    
// echo what you want
    
unset($_SESSION["success"]); // So the message doesn't always show up
} 

Hope this helped!

I appreciate the response, but it doesn't appear to go away. I can visit the homepage and it will be there, even if I didn't submit a form. Thisi s how I have it set up

PHP Code

<?php
if (isset($_SESSION["sent"])) {
 
// Start
?>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script> 
$(document).ready(function(){
  $("#flip").click(function(){
    $("#panel").slideToggle("slow");
  });
});
</script>

<style> 
#panel,#flip
{
padding:2px;
text-align:center;
background-color:#00BFFF;
border:solid 1px #c3c3c3;
}
#panel
{
padding:15px;
display:none;
}
</style>
<body>

<div id="flip">Success!</div>
<div id="panel">Your form has been submitted. <b>If</b> your form required being contacted, you will be contacted ASAP.</div>

</body>
</html> 
<?php
//End
    
unset($_SESSION["sent"]); // So the message doesn't always show up
} 

I would appreciate a quick response, I'm trying to get this published soon. 🤝

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
PHP Code

<?php
session_start
();
if (isset(
$_SESSION["sent"])) {
 
// Start
?>
Make sure you call session_start() before ANY output!
You see, Doctor, God didn't kill that little girl. Fate didn't butcher her and destiny didn't feed her to those dogs.
If God saw what any of us did that night he didn't seem to mind. From then on I knew... God doesn't make the world this way.
We do.
(Dec 16, 2014 08:27 AM)Squito Wrote:  
PHP Code

<?php
session_start
();
if (isset(
$_SESSION["sent"])) {
 
// Start
?>
Make sure you call session_start() before ANY output!
So I updated it to this

Home Page:
PHP Code

<?php 
[b]<!--[/b] PHP session beginning -->
<?
php
session_start
();
if (isset(
$_SESSION["sent"])) {
 
// Start
?>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script> 
$(document).ready(function(){
  $("#flip").click(function(){
    $("#panel").slideToggle("slow");
  });
});
</script>

<style> 
#panel,#flip
{
padding:2px;
text-align:center;
background-color:#00BFFF;
border:solid 1px #c3c3c3;
}
#panel
{
padding:20px;
display:none;
}
</style>
<body>

<div id="flip"><b>Submitted!</b> (Click for more)</div>
<div id="panel">Your form has been submitted. If your form required being contacted, you will be contacted ASAP.</div>
</body>
</html>
<?php
session_start
();
// terminate the session
session_destroy();
?>
[b]<!--[/b] PHP Session end. Displays sent information only when sent --> 
Contact submit page:
PHP Code

<?php
session_start
();
$_SESSION["sent"] = true;  // or any value really
?>
It still didn't go away from the homepage, even though I didn't submit a form. Why is this happening?

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
Something like this should work :

PHP Code

<?php 
if(isset($_POST['submit'])) {
    
// user submited the form
}
<
form method="post" ...>
    <
input type="submit" name="submit" />
</
form> 

By the way, post in PHP Section next time
(Dec 16, 2014 09:26 AM)Sakuto Wrote:  Something like this should work :

PHP Code

<?php 
if(isset($_POST['submit'])) {
    
// user submited the form
}
<
form method="post" ...>
    <
input type="submit" name="submit" />
</
form> 

By the way, post in PHP Section next time

I appreciate your response, I did infact create a new thread there, because I realized it fits there, better.

Could you expand on this? Where am I supposed to place that?

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
(Dec 16, 2014 09:33 AM)Nachfolger Wrote:  I appreciate your response, I did infact create a new thread there, because I realized it fits there, better.

Could you expand on this? Where am I supposed to place that?

Definitely don't do that POST method thing he's doing.
If I'd have to guess I'd have to assume you're missing the unset method call on the variable on the page where it shows up, put that and the end of the if block.
(Dec 16, 2014 03:29 PM)const Wrote:  Definitely don't do that POST method thing he's doing.
If I'd have to guess I'd have to assume you're missing the unset method call on the variable on the page where it shows up, put that and the end of the if block.

Ow, why ? Please explain your point of view.
(Dec 16, 2014 03:29 PM)const Wrote:  Definitely don't do that POST method thing he's doing.
If I'd have to guess I'd have to assume you're missing the unset method call on the variable on the page where it shows up, put that and the end of the if block.

Could you post the corrected code? I'm not exactly sure where it's supposed to be placed.

Also, why should I not use the post method? Just curious, I didn't use it anyway.

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
(Dec 16, 2014 08:35 AM)Nachfolger Wrote:  It still didn't go away from the homepage, even though I didn't submit a form. Why is this happening?
I told you that you have to call session_start() before ANY output. HTML comment is also an output.

php.net Wrote:To use cookie-based sessions, session_start() must be called before outputing anything to the browser.
You see, Doctor, God didn't kill that little girl. Fate didn't butcher her and destiny didn't feed her to those dogs.
If God saw what any of us did that night he didn't seem to mind. From then on I knew... God doesn't make the world this way.
We do.
Print an extra hidden? On your form send an extra param like : show

then php print a html hidden :
PHP Code

<?php 
if(isset($_POST['show'])) { echo '<hidden id = "showit">'; } 

Then with jquery on
PHP Code

<?php 
$(function(){}); 
do something like :
PHP Code

<?php 
if($('#showit').length) 

to check if your hidden exist and if its the case then do the rest of the work.
Accepting freelancing jobs ! PM me for more info !
Be the [BRAND NAME REMOVED] king ..


Possibly Related Threads...
Thread / Author Replies Views Last Post
by ΣռէifվOct 21, 2015 07:03 PM 0 74 Oct 21, 2015 07:03 PM
Last Post: Σռէifվ
by severosFeb 24, 2015 09:30 PM 2 97 Feb 24, 2015 09:30 PM
Last Post: severos
by ConsoleTVsNov 27, 2014 02:07 AM 3 110 Nov 27, 2014 02:07 AM
Last Post: ConsoleTVs