How to pass variable to new page?
I have a question.
It is possible to pass variable to a new page to a new page... without method
GET
. But it's visible.Is it possible to pass variable to a new page to a new page... with method
POST
without a form ?Is it possible to get variable to a new page with
ajax
?
I need to pass ID from a page to another page to another page... without that the visitor 开发者_如何转开发sees the variable in URL.
EDIT : Yes, I tought to session but when I go to home, I need to delete this session. Is it really a good idea to use session ?
EDIT : Which is the best way ? COOKIE
OR SESSION
Thanks
I think you want sessions:
Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site. All information is in the Session reference section.
The first page can put the ID in the session and the other page can retrieve it.
You will want to take a look at sessions
This allows you to set a variable like so: $_SESSION['my_var'] = $my_Var;
You will then be able to pass this variable around the different pages. You return the variable by calling $_SESSION['my_var']
.
Remember though, that on each page you use sessions you need to have session_start();
at the top of each page.
Cookies is what you are looking for. You can set the page id in cookie value, and then using $_COOKIE
, retrieve it. Though, it might not work if using multiple/different hosts.
Also, using AJAX, you can also make POST requests along with GET. Frameworks like jQuery, Mootools, etc. allow this easily.
If it's on the same server, you can use sessions but if it's across two different servers, you can post via cURL
Beside using sessions, you can write the variable to the database first.
精彩评论