单击链接时将URL变量传递给php

单击链接时将URL变量传递给php,php,url,Php,Url,我的URL来自:locahhost/index1.php?option=com\u lsh&view=lsh&event\u id=xxxxx&tv\u id=xxx&tid=xxxx&channel=x 当用户单击此链接时,文件index1.php应处理此URL,然后生成 此表单中的新URL localhost/static/popups/xxxxxxxxxx.html,其中xxxxxxxxxxxx是 活动id、电视id、tid和香奈儿 为此,我在文件index1.php中使用parse ur

我的URL来自:
locahhost/index1.php?option=com\u lsh&view=lsh&event\u id=xxxxx&tv\u id=xxx&tid=xxxx&channel=x

当用户单击此链接时,文件
index1.php
应处理此URL,然后生成

此表单中的新URL localhost/static/popups/xxxxxxxxxx.html,其中xxxxxxxxxxxx是

活动id、电视id、tid和香奈儿

为此,我在文件
index1.php
中使用parse url函数,如下所示:

<?php
$url = 'http://localhost/index1.php?option=com_lsh&view=lsh&event_id=&tv_id=&tid=&channel=';
$parsed = parse_url( $url );
parse_str( $parsed['query'], $data );
$newurl = 'http://localhost.eu/static/popups/'.$data['event_id'].$data['tv_id'].$data['tid'].$data['channel'].'.html';
header("Location: $newurl");
?>

但它不起作用,我认为这是由于
$url='1'中的某些错误造成的http://localhost/index1.php?option=com_lsh&view=lsh&event_id=&tv_id=&tid=&channel=';


这有什么问题?例如,当tv_id不存在于url中时,我需要它,而将0放入新url中。parse_url函数用于获取给定的url并将其转换为其组成部分。 您要查找的是从$\u GET数组访问变量

我假设您的事件ID是一个整数

$event_id=(int)$_GET['event_id'];
$new_url=''http://localhost.eu/static/'.$event_id // and so forth

如果您希望某个变量中包含文本而不是数字,请对其进行进一步清理。

$newUrl
格式不正确。在
$data['tv\u id'
之后缺少一个紧括号
]


$newurl='1!'http://localhost.eu/static/popups/“.$data['event\u id']。$data['tv\u id'.$data['tid']。$data['channel']..html”;

您忘了关闭$new\u url中的tv\u id数组标记

$newurl = 'http://localhost.eu/static/popups /'.$data['event_id'].$data['tv_id'].$data['tid'].$data['channel'].'.html';
返回:

http://localhost.eu/static/popups/0000.html

更新: 您不需要生成$url变量并将其解析为值数组。 当用户单击链接时,数据会附带
GET
方法。如果使用
GET
POST
而不是$url,只需使用$\u REQUEST['variable'](或$\u GET[']或$\u POST[''])


每个人在发布问题时都忽略了这一点,但我在尝试时已经关闭了括号。我的问题是关于$url的,我认为代码遗漏了一些内容。从用户单击的url中提取变量,将其传输到Popop url中的正确新url,值之间是否有分隔符?@user2338253我想编辑你的问题,使其包含缺少的括号,这样我们就不会因此而偏离轨道。这里是我使用你的代码的地方,但没有工作,对吗?@Andrey volk你的代码很好,但有一个问题,如何从用户c的链接传输这些值
事件id',电视id',tid',频道
点击$url。很好,它工作得很好,完成了工作,谢谢你。先生,你的另一个帮助是假设新的url是
http://remotesite.com/static/popups/xxxxxxxxxxxx.html
我需要获取该url的源代码,并在下面的路径mydo中创建新的html文件,名称为xxxxxxxxx.html,而不是回显该urlmain/static/popups并将用户重定向到此文件看一看是的,我不知道如何使用文件put内容,但我使用的是相同的
fopen()、fwrite()和fclose()
但是我的问题是关于文件名的,因为你知道每次xxxxxxxx.html都会有不同的文件名。我不知道如何在代码中编写这个文件?但是,谢谢你终于解决了我的问题,作为一个新手,这个问题困扰了我三天
http://localhost.eu/static/popups/0000.html
$keys = array('event_id', 'tv_id', 'tid', 'channel'); // order does matter
$newurl = 'http://localhost.eu/static/popups/';
foreach ($keys as $key)
    $newurl.= empty($_REQUEST[$key])?0:$_REQUEST[$key];

$newurl.='.html';

echo $newurl;