Different ways of passing variables with data between pages

Variables between Pages We often have to pass values of variables between pages in our site. These are required in many different ways. Some time we collect some value from a database and want to retain the value for the particular user throughout the site as the user moves between pages. There are different ways for passing such values of the variables. It can be passed within a site or even outside the site. We will discuss some of the ways with their possible uses.
Passing variable with data to different pages

Passing variable values between pages using session

This is one of the secured ways the variables are passed between pages. The best example of such a system is when we see our user-id inside a member area after we logged in. In a member login system the user details are verified and once found correct, a new session is created and with user id of the member and this value is stored at server end. Every time a new page is opened by the browser, the server checks the associated session value and display the user id. This system is more secure and the member doesn't get any chance to change the values. For more details on session variables & its management read this.

Passing variables between pages using cookies

Cookies are stored at the user or the client end and values can be passed between pages using PHP. But here the client browser can reject accepting cookies by changing the security settings of the browser. So this system can fail to pass values between pages if user or client end settings are changed. But cookies are quit useful in handling user entered values and passing them between pages. Read more details on handling cookies in PHP

Passing variables between pages using URL

We can pass variable values between pages through the URL ( in address bar of the browser). Here values are visible to the user and others as they appear in the address bar and also in the browser history. This is not a secure way to transfer sensitive data like password, etc. Read more on how to pass variables between pages using URL.

Web Forms

Forms are used mainly to collect data and then transfer them to a processing page. Here the processing page uses one of the above methods to pass values to different pages as per the requirements. Forms can be used to pass values to different sites. Forms can submit the data to a processing script running at a different URL in different server.

These are some of the way of transferring data variables between pages. There is no clear rule to use a particular method to pass the variables between pages. Here are some standard way of doing with reasons. All variables needs sanitization before using when they arrive from external sources.
Login form with Userid and password POSTId and password should not be visible in query string
Sending Product id GET The url can be bookmarked for future uses.
Feedback form Post Several data can be posted
Favorite buying pattern of User Cookies Data stored in user computer
User Login status Session Secured data is maintained at server end

Passing data from PHP to JavaScript

JavaScript runs at client side , where PHP runs at server end. We can pass data from PHP to JavaScript by sending the data to client end.
$php_variable = "hello world"; // Declaring PHP variable 
echo "<script>var js_variable = \"$php_variable\";</script>"; // Passing to JavaScript variable
document.write(js_variable); // JavaScript output  
Declaring variables Transfer variables between pages and between sites Cookies to store Infomation
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net




    thanks a lot for such good material of php.


    I want , How to pass Javascript variable value to PHP Variable


    Without reloading the page we can't pass JavaScript variable to PHP script. We can use Ajax to do that.


    I want a script that will allow me to pass values in php variables on to a different form


    I just want to play the variable between php and javascript.
    Harsh karwal


    hi, i am a fresher in PHP and trying to learn it. i need a code for display data on another page when some one submit his details like his name, his mbl no., his age etc.. in a form and after click on submit button the same data is display.


    i have fill the value in textbox when click the button value are pass to new screen .How to pass the value?


    You can pass data from child window to parent window and same way you can try by reversing.

    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer