douruhu4282 2013-05-06 17:55
浏览 70
已采纳

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

I have URL in this from: locahhost/index1.php?option=com_lsh&view=lsh&event_id=xxxxx&tv_id=xxx&tid=xxxx&channel=x

when the user click this link, the file index1.php should process this the URL then produce

new URL in this form localhost/static/popups/xxxxxxxxxxx.html wher xxxxxxxxxxxxx is the

event_id, tv_id, tid and chanel.

to do this I am using parse url function in the file index1.php as following :

<?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");
?>

but its not working i think this is due to something wrong in $url = 'http://localhost/index1.php?option=com_lsh&view=lsh&event_id=&tv_id=&tid=&channel=';

what is wrong with this? also i want it when for example tv_id not present in the url it put instead 0 in the newurl

  • 写回答

4条回答 默认 最新

  • dongzi0602 2013-05-06 18:32
    关注
    $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 );
    
    $keys = array('event_id', 'tv_id', 'tid', 'channel'); // order does matter
    $newurl = 'http://localhost.eu/static/popups/';
    foreach ($keys as $key)
        $newurl.= empty($data[$key])?0:$data[$key];
    
    $newurl.='.html';
    
    echo $newurl;
    

    returns:

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

    UPDATE: You do not need to make an $url variable and parse it into an array of values. When user clicks a link data comes with GET method. If you use GET or POST instead of $url, just use $_REQUEST['variable'] (or $_GET[''] or $_POST[''])

    $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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?