Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Ways to get data from one page to another page in PHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 110
    Comment on it

    Hello Readers

    In php there are many different ways to get the data from one page to another page in php.

    1. Using session by passing values between pages: This is the one of the method to get the data from one page to another page in php and this is the secured method to pass values between pages.

    For example:

    When the user login into the application then the details of the user are verified and if found true a new session is generated after that the userId save on server (server side) after that the new page open on browser, server makes a check for the session value and show the userId.

    For example:

    $_SESSION['session_name'] = $session_value;
    

    Before using the above $_SESSION variable use to start first session using session_start() statement on top of the page

    1. Using cookies by passing values between pages: We now that cookie work on client side. However, the clients browser can change the settings and thus reject accepting cookies.

    Therefore, the system may fail in passing variables between pages. In such type, of conditions cookies are found useful in handling user entered variables and then passing those between pages.

    But cookie is less secure therefore we cannot pass or send sensitive value like password using this method.

    Example for set cookie:

    setcookie("set_cookie_name", $cookie_value, time()+3600);
    

    Using cookie get method we can get the same value in other page.

    $var_value = $_COOKIE['set_cookie_name'];
    
    1. Passing values between pages using URL: In php variables can se passed through pages by using the URL in the address bar of the browser.

    Using this, users can view the values in the address bar as well as in the browser's history folder.

    For Example:

     http://discussdesk.com/index.php?id=5&name=discussdesk
    

    If we can get the id value using GET method.

     $id = $_GET[id];
     $name = $_GET[name];
    

    But this method is not considered secure for tansfering the sensitive information for example the users profile details or password.Because the $_GET (superglobal variable) is not secure never send any sensitive data using URL method. So, we cannot send more amounts of data by using this method.

    So, we have a another method POST by using POST method in form submission, we can send more amounts of data from one page to another page.

    Using this method, the data is invisible so we can send more secure data like password, online transaction etc.

    For Example:

    We have a form set the action post to post the data

    And we can get any data value inside this form using.

     $id=$_POST['id'];
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: