doujiu5464 2015-06-18 04:04
浏览 44
已采纳

将变量从一个页面传输到另一个页面[关闭]

I derived the data from database and stored like that in php

<tr>
<td><a href=SMSindex.php?tp_no=$row[tel] >
     <img src=images/phone.png width=30 height=30 >
    </a>
</td>
<td>".$row["name"]."</td> </tr>

when I click the phone.png image, the SMSindex.php want to echo they phone number without show in the URL.(if is just use $_GET[tel] get the answer but same time i can see in the same phone no in url also.)

(the problem solved by Mr.Sulthan Allaudeen)

  • 写回答

1条回答 默认 最新

  • doushang2571 2015-06-18 04:18
    关注

    You can use sessions to achieve this.

    You have a syntax error here.

    <td>".$row["name"]."</td> </tr>
    

    It shall be fixed by

    <td><?php echo $row['name'] ?></td> </tr>
    

    [ Or the way Hanky 웃 Panky suggested ]

    You can have it in your session by

    <?php
    session_start();
    $_SESSION['name'] = $row['name']
    ?>
    

    And retrieve it on another page by

    <?php
    session_start();
    echo $_SESSION['name'];
    ?>
    

    Update :

    If you have this in your url and you want to have your tp_no globally available then you should replace the $row['name'] by $_GET['tp_no']

    http://localhost:88/web/SMSindex.php?tp_no={%27tel:94771122336%27}
    

    You should get the tp_no by

    $_GET['tp_no']
    

    But I don't know the reason you wrap around {}

    Update :

    As you don't want to see the url in the page.

    Here's a tiny workaround to overcome it.

    <?php
    session_start();
    if (isset($_GET['tp_no'])) 
    {
    $_SESSION['tp_no'] = $_GET['tp_no'];
    unset($_GET['tp_no']);
    $url = $_SERVER['SCRIPT_NAME'].http_build_query($_GET);
    header("Refresh:0; url=".$url);
    }
    elseif (isset($_SESSION['tp_no'])) 
    {
    echo $_SESSION['tp_no'];
    session_unset();
    session_destroy();
    }
    else
    {
        echo "Direct / Illegal Access not allowed";
    }
    ?>
    

    An Explained Version

    <?php
    session_start();    #Starting the Session
    if (isset($_GET['tp_no']))  #Checking whether we have $_GET value from the url 
    {
    $_SESSION['tp_no'] = $_GET['tp_no']; # We are assiging the tp_no to session
    unset($_GET['tp_no']); #Here we are unsetting the value that we get from url
    $url = $_SERVER['SCRIPT_NAME'].http_build_query($_GET); #Here we are removing gettgint the url and removing the tp_no from it 
    header("Refresh:0; url=".$url); #Now we are redirecting/refreshing the page with tp_no - As you said you need it :)
    }
    elseif (isset($_SESSION['tp_no']))  
    #Here is the else if condition once we refresh the page we won't have $_GET so the it will come inside this loop
    {
    echo $_SESSION['tp_no']; #Displaying the value that is from the session
    session_unset();     #Unsetting the session value for secure
    session_destroy();   #Destroying the entire session value for secure
    }
    else
    {
    #The compiler will come to this part if both session or url is not set, So this is illegal area
        echo "Direct / Illegal Access not allowed";  
    #There might be some hackers/genius persons who will try to access directly this page, to avoid them we are showing them the above warning message
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集