在 PHP 中将复杂的 URL 作为参数传递 [英] Pass complex URL as parameter in PHP

查看:32
本文介绍了在 PHP 中将复杂的 URL 作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将复杂的 URL 作为 url 参数传递,但如果 url 包含 &例如我想将以下链接作为参数传递

I'm trying to pass a complex URL as a url parameter but the problem occurs if the url contains & for example I want to pass the following link as a parameter

http://www.google.ps/search?hl=en&client=firefox-a&hs=42F&rls=org.mozilla%3Aen-US%3Aofficial&q=The+type+%27Microsoft.Practices.ObjectBuilder.Locator%27+is+defined+in+an+assembly+that+is+not+referenced.+You+must+add+a+reference+to+assembly+&aq=f&aqi=&aql=&oq=

我试图从用户那里获取一个 URL 作为参数并将用户重定向到这个 URL.

I'm trying to get a URL as a parameter from a user and redirect user to this URL.

我如何在 PHP 中处理这个问题?

How could I handle this in PHP?

整个故事:

我正在尝试对 Flash 文件进行一些广告分析,以便用户将 Flash 广告提交到包含指向所需网页的链接的网站.

I'm trying to make some ads analytics on flash files so user submit flash ads to a website which contains a link to the required webpage.

现在,我的客户需要知道这个 Flash 文件被点击了多少次.为了解决这个问题,我将直到每个提交 Flash 的人写一个链接到我的客户网页并将所需的 URL 作为参数传递如下

Now,my client needs to know how many times this flash file was clicked.To solve this I 'll till every one who submits flash to write a link to my client webpage and pass the required URL as a parameter as follows

http://myclientwebpage.com/disp.php?link=www.google.com&id=16

通过这种方式,我可以更新我的数据库并计算此链接被点击的次数

by this way I can update my database and get a count for how many times this link was clicked

推荐答案

使用 urlencode()rawurlencode().

你写道:

我正在尝试获取 URL 作为参数从用户并将用户重定向到此网址.

I'm trying to get a URL as a parameter from a user and redirect user to this URL.

但是你没有回答这个问题——你是如何获得那个 URL 的?用户如何提供给你?是用写的吗?或者用户是否单击某个包含 URL 作为参数之一的链接?或者作为某个存储在数据库中的 URL 的 ID 传递?

But you didn't answer the question - how do you get that URL? How does user provide you with it? Is it written in <input type='text'/>? Or does user click some link that contains URL as one of parameters? Or is passed as ID of some URL that is stored in DB?

我想到的一种情况 - 以纯文本形式替换 URL 并在打开真实页面之前将用户发送到某个重定向页面",因此最终页面看不到可能包含一些安全数据(例如,会话 ID)的 HTTP 引荐来源网址.在这种情况下,你会写

One case that comes into my mind - replacing URLs in plain text and sending user to some "redirecting page" before opening real page, so final page does not see HTTP referrer which might contain some secure data (e.g., session ID). In this case, you would write

<a href='redirect.php?link=<?php echo rawurlencode($url); ?>'>
    <?php echo htmlspecialchars($url); ?>
</a>

代替

<a href='redirect.php?link=<?php echo $url; ?>'>
    <?php echo htmlspecialchars($url); ?>
</a>

这篇关于在 PHP 中将复杂的 URL 作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆