Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: How to use Session in PHP like ASP

  1. #11
    Join Date
    Mar 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by borris83 View Post
    Hi, Make sure that you have these things right:

    The command php session_start() ; should appear before any other html code and it should appear on both the pages....


    You also have to assign all the variables of array $_REQUEST to the array $_SESSION

    for eg:

    $_SESSION['nameofproduct'] = $_REQUEST['nameofproduct'] ;
    $_SESSION['priceusd'] = $_REQUEST['priceusd'] ;


    and in thanks.php, you have to echo the values of $_SESSION['nameofproduct'], $_SESSION['priceusd'] and so on

    Remember, the function session_start() ; should appear before your very first html code on the page.. If there is even one html code before session_start(), the it might not work
    Thanks for the reply borris83

    I am testing this and would let you know if this works .

    Thanks to all of you for your priceless time.

  2. #12
    Join Date
    Mar 2009
    Location
    Egypt
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by paramjeetgemini View Post
    Thanks for the reply Ahmed Saleh. Actually ditto same thing I had already tried just 2 days ago before your reply. It works as well. But even this has some issue. When someone refreshes/Click Back Button of Browser in the Thanks.php Page (which is actually now working as send.php as well because the Thanks.php & Send.php are one file), the form gets submitted again and a new order code etc. gets generated.

    Is it possible that if someone refreshes or click browser back button the form does not get submitted again ?

    I know , kindely you can add this code at the end :

    PHP Code:
    echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"3; url=the form url here\">"
    replace : the form url here
    write : the form page name , like index.php .

    and it will fine ...

    Try and let me know the result .

  3. #13
    Join Date
    Mar 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Ahmed Saleh View Post
    I know , kindely you can add this code at the end :

    PHP Code:
    echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"3; url=the form url here\">"
    replace : the form url here
    write : the form page name , like index.php .

    and it will fine ...

    Try and let me know the result .
    Thanks Ahmed Saleh.

    But Where should this line be added in the code?

    PHP Code:
    echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"3; url=the form url here\">"
    I mean in send.php file ? If yes, then where should this line be written ?

    At top where variables are declared ? or at the end ?

    Waiting for the reply...

  4. #14
    Join Date
    Mar 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Dear Ahmed Saleh,

    Actually I tried it somewhere in my send.php (which now also working as thanks page as well). But issue is the page gets refreshed back to the Form by using the code:
    PHP Code:
    echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"3; url=order.htm\">"
    I am looking for something if someone clicks on BACK BUTTON in BROWSER, the message should be that the page has expired or something similar. And this way, the form will not get submitted again or atleast the send.php will not get executed again.

    By refereshing send.php file (i.e. now it is a thanks page), the code gets executed on the server once again.

    Can we add any line at the bottom of send.php so that this page, even if refereshed, does nothing ?

  5. #15
    Join Date
    Mar 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by borris83 View Post
    Hi, Make sure that you have these things right:

    The command php session_start() ; should appear before any other html code and it should appear on both the pages....


    You also have to assign all the variables of array $_REQUEST to the array $_SESSION

    for eg:

    $_SESSION['nameofproduct'] = $_REQUEST['nameofproduct'] ;
    $_SESSION['priceusd'] = $_REQUEST['priceusd'] ;


    and in thanks.php, you have to echo the values of $_SESSION['nameofproduct'], $_SESSION['priceusd'] and so on

    Remember, the function session_start() ; should appear before your very first html code on the page.. If there is even one html code before session_start(), the it might not work
    No dear, this still does not work. I mean No Error but not able to fetch values in thanks.php

  6. #16
    Join Date
    Mar 2009
    Location
    Egypt
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    if you want show : page expired message
    put this at the first on send.php .


    PHP Code:

    header
    ("Cache-Control: no-cache, must-revalidate");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
    Now your script is working so good and like you want to be .

  7. #17
    Join Date
    Mar 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Dear Ahmed Saleh,

    Thanks once again for your help. But even after placing this code at top of my send.php, I am able to refresh it (i.e. thanks confirmation page). The form gets submits again, the order gets generated again

    Hope there is a way so that even if someone refreshes the thanks confirmation page, it does not submits the form again.

    Anyway, thanks a lots for your time.

Bookmarks

Posting Permissions

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