如何将变量传递到新页面?

时间:2022-03-09 21:15:26

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 ?

    是否可能将变量传递到新页面到新页面……没有表单的方法POST ?

  • Is it possible to get variable to a new page with ajax ?

    是否可以使用ajax将变量转换为一个新页面?

I need to pass ID from a page to another page to another page... without that the visitor sees the variable in URL.

我需要把ID从一个页面传递到另一个页面。否则访问者会看到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

谢谢

5 个解决方案

#1


2  

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.

PHP中的会话支持包含了在后续访问中保存某些数据的方法。这使您能够构建更自定义的应用程序,并增加web站点的吸引力。所有信息都在会话参考部分。

The first page can put the ID in the session and the other page can retrieve it.

第一页可以将ID放在会话中,另一页可以检索它。

#2


1  

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'].

这允许您设置如下变量:$_SESSION['my_var'] = $ my_var;然后,您将能够在不同的页面中传递这个变量。通过调用$_SESSION['my_var']返回变量。

Remember though, that on each page you use sessions you need to have session_start(); at the top of each page.

但是请记住,在使用会话的每个页面上,都需要有session_start();在每一页的顶部。

#3


1  

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.

饼干是你要找的。您可以在cookie值中设置页面id,然后使用$_COOKIE检索它。但是,如果使用多个/不同的主机,它可能无法工作。

Also, using AJAX, you can also make POST requests along with GET. Frameworks like jQuery, Mootools, etc. allow this easily.

此外,使用AJAX,您还可以随GET一起发出POST请求。像jQuery、Mootools之类的框架很容易做到这一点。

#4


0  

If it's on the same server, you can use sessions but if it's across two different servers, you can post via cURL

如果它在同一个服务器上,您可以使用会话,但是如果它跨两个不同的服务器,您可以通过cURL发布

#5


0  

Beside using sessions, you can write the variable to the database first.

除了使用会话,还可以先将变量写入数据库。

#1


2  

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.

PHP中的会话支持包含了在后续访问中保存某些数据的方法。这使您能够构建更自定义的应用程序,并增加web站点的吸引力。所有信息都在会话参考部分。

The first page can put the ID in the session and the other page can retrieve it.

第一页可以将ID放在会话中,另一页可以检索它。

#2


1  

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'].

这允许您设置如下变量:$_SESSION['my_var'] = $ my_var;然后,您将能够在不同的页面中传递这个变量。通过调用$_SESSION['my_var']返回变量。

Remember though, that on each page you use sessions you need to have session_start(); at the top of each page.

但是请记住,在使用会话的每个页面上,都需要有session_start();在每一页的顶部。

#3


1  

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.

饼干是你要找的。您可以在cookie值中设置页面id,然后使用$_COOKIE检索它。但是,如果使用多个/不同的主机,它可能无法工作。

Also, using AJAX, you can also make POST requests along with GET. Frameworks like jQuery, Mootools, etc. allow this easily.

此外,使用AJAX,您还可以随GET一起发出POST请求。像jQuery、Mootools之类的框架很容易做到这一点。

#4


0  

If it's on the same server, you can use sessions but if it's across two different servers, you can post via cURL

如果它在同一个服务器上,您可以使用会话,但是如果它跨两个不同的服务器,您可以通过cURL发布

#5


0  

Beside using sessions, you can write the variable to the database first.

除了使用会话,还可以先将变量写入数据库。