...

View Full Version : Display some text only for the first page load



levani
08-29-2009, 10:58 AM
How can I display some message only for the first page load. I have a wordpress blog and would like to display thank you message after I user adds comment for example. Is that possible using php?

Zangeel
08-29-2009, 11:22 AM
Yes, if the comment is not using ajax, use post data for example



if (isset($_POST['submit']))
{
echo 'Thank you for submitted your comment!';
}


$_POST['xxx'] highlighted would be the name of the posted data, for example


<input type="submit" name="submit" />

then to see if that piece of data was sent through a form we would do


if (isset($_POST['submit']))
{
// do whatever
}

levani
08-29-2009, 12:36 PM
Yes, if the comment is not using ajax, use post data for example



if (isset($_POST['submit']))
{
echo 'Thank you for submitted your comment!';
}


$_POST['xxx'] highlighted would be the name of the posted data, for example


<input type="submit" name="submit" />

then to see if that piece of data was sent through a form we would do


if (isset($_POST['submit']))
{
// do whatever
}


Sorry, but this code doesn't work :( It seems the form is redirected to somewhere and than returns back to site...

whizard
08-29-2009, 02:46 PM
Maybe use create an array in a session that holds all the pages, and whether the user has been there? Tedious, but only way I can think of in your situation.

Dan

Zangeel
08-30-2009, 01:43 AM
Hm, is it like a wordpress script you're using? If it redirects you, just get the referrer, so let's say it redirects you to post.php, posts, then redirects you back to the page, you can check if they came from post.php then display the message.

Example


if ($_SERVER['HTTP_REFERRER'] == ...)
{
echo 'You came from ...';
}

levani
08-30-2009, 08:55 AM
Hm, is it like a wordpress script you're using? If it redirects you, just get the referrer, so let's say it redirects you to post.php, posts, then redirects you back to the page, you can check if they came from post.php then display the message.

Example


if ($_SERVER['HTTP_REFERRER'] == ...)
{
echo 'You came from ...';
}

Yes, it's wordpress. After clicking the submit button it's redirected to the wp-comments-post.php file, which is in main directory. What would the code look like?

Is it right?

if ($_SERVER['HTTP_REFERRER'] == 'wp-comments-post.php')
{
echo 'You came from ...';
}

levani
08-31-2009, 11:44 AM
?????

Scriptet
08-31-2009, 01:31 PM
How can I display some message only for the first page load. I have a wordpress blog and would like to display thank you message after I user adds comment for example. Is that possible using php?


You kind of contradict yourself, do you want a message on the first page load, or after somebody adds a comment, or what?

levani
08-31-2009, 01:35 PM
You kind of contradict yourself, do you want a message on the first page load, or after somebody adds a comment, or what?

Actually both :) I want to display a message when somebody adds comments but only for the first page load :)

Scriptet
08-31-2009, 01:46 PM
So after a comment is posted, it redirects to wp-comments-post, does it display a message on here or where does it go after this?

Do you want the message to appear on the wp-comments-post or another page

levani
08-31-2009, 02:12 PM
Yes, after I click comment form submit button the form is redirected to the wp-comments-post.php and automatically returns to the previous page.

I don't want to appear message in wp-comments-post. The redirection is so fast, the wp-comments-post isn't even seen in browser address bar.

Scriptet
08-31-2009, 02:48 PM
Ah I understand now, so really we need to perform a check on the page it's redirecting to.
You can indeed do what Zangeel suggessted earlier in post 5..

I'm assuimg you'd probably add this into your single.php file, seeing as comments can only be added to single post pages in Wordpress? So it will always redirect to this?

levani
09-01-2009, 02:03 PM
Ah I understand now, so really we need to perform a check on the page it's redirecting to.
You can indeed do what Zangeel suggessted earlier in post 5..

I'm assuimg you'd probably add this into your single.php file, seeing as comments can only be added to single post pages in Wordpress? So it will always redirect to this?

Yes comments are always redirected to that file and I'm adding this code in single.php (as it's redirected and returned to single.php) but it doesn't seem to work...

Is that a right code?:

if ($_SERVER['HTTP_REFERRER'] == 'wp-comments-post.php')
{
echo 'Thanks for adding comments.';
}

levani
09-01-2009, 05:10 PM
The redirection is automatic and no link is clicked in wp-comments-post.php, will it still work?

And please somebody tell what the code would look like.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum