Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post

    Display some text only for the first page load

    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?

  • #2
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    Yes, if the comment is not using ajax, use post data for example

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

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

    Code:
    <input type="submit" name="submit" />
    then to see if that piece of data was sent through a form we would do

    PHP Code:
    if (isset($_POST['submit']))
    {
       
    // do whatever

    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #3
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Zangeel View Post
    Yes, if the comment is not using ajax, use post data for example

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

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

    Code:
    <input type="submit" name="submit" />
    then to see if that piece of data was sent through a form we would do

    PHP Code:
    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...
    Last edited by levani; 08-29-2009 at 01:40 PM.

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    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
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    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

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

    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #6
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Zangeel View Post
    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

    PHP Code:
    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?
    PHP Code:
    if ($_SERVER['HTTP_REFERRER'] == 'wp-comments-post.php')
    {
    echo 
    'You came from ...';


  • #7
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    ?????

  • #8
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    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?

  • #9
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Scriptet View Post
    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

  • #10
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    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

  • #11
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    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.

  • #12
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    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?

  • #13
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    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?:
    PHP Code:
    if ($_SERVER['HTTP_REFERRER'] == 'wp-comments-post.php')
    {
    echo 
    'Thanks for adding comments.';


  • #14
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •