简体   繁体   English

在PHP页面之间传递URL

[英]Pass URLs between php pages

I was wondering how I can pass a URL to another web page using PHP. 我想知道如何使用PHP将URL传递到另一个网页。 I know if I were to use an HTML form I could have a hidden field with the value being the URL I want to get. 我知道如果我要使用HTML表单,则可以有一个隐藏字段,其值为我要获取的URL。

How can I pass the URL along to another page without using a form? 如何不使用表单将URL传递到另一个页面?

If the page is your own, you could use a session variable. 如果页面是您自己的,则可以使用会话变量。

More details here: http://www.w3schools.com/php/php_sessions.asp 此处有更多详细信息: http : //www.w3schools.com/php/php_sessions.asp

您可以使用$_SESSIONcookie

PHP has a server global variable which includes a referrer variable. PHP具有服务器全局变量,其中包括引用程序变量。

$_SERVER['HTTP_REFERER']

http://php.net/manual/en/reserved.variables.server.php http://php.net/manual/en/reserved.variables.server.php

You can echo this and it will output the page which the user came from. 您可以回显此内容,它将输出用户来自的页面。

You could pass it using a get query,which is in a way form data, so i won't go into it OR a session variable. 您可以使用get查询(通过某种形式的数据传递)来传递它,因此我不会涉及它或会话变量。 On the sender page 在发件人页面上

session_start();
$_SESSION['url']="http://site.com"

and on the receiver 在接收器上

session_start();
$url=$_SESSION['url'];
unset($_SESSION['url'])l

You can initiate sessions. 您可以发起会话。

Put session_start(); 把session_start(); at the top of every page (normally by including a header or function). 在每个页面的顶部(通常通过包含标题或函数)。 The session_start(); session_start(); needs to come before any HTML output. 需要先于任何HTML输出。

Then on your referring page, you can save values into the session array: $_SESSION['URL'] = "myurl.com"; 然后,在引荐页上,您可以将值保存到会话数组中:$ _SESSION ['URL'] =“ myurl.com”;

On your second page, you can reference it just like any other variable: echo $_SESSION['URL']; 在第二页上,您可以像引用其他任何变量一样引用它:echo $ _SESSION ['URL'];

<a href="somepage.php?url=<?php echo urlencode("http://example.com/page"); ?>">Link</a>

然后, somepage.php将在变量$_GET['url']接收URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM