dongweihuai5601 2012-07-04 11:24
浏览 40
已采纳

在重定向函数中使用变量

With PHP, I have a script that searches for an email from a mysql_db then takes a username from the same row as the email in the db. What I want it to do is redirect using the username as a subdomain in the url

I've tried:

 $username = //username taken from the db
 $url = 'http://".$username."domain.com';
 header('location: $url');

This just appends the variable "$url" to the end of my test url.

and I've tried:

header('http://".$username."domain.com');

This outputs in the adress bar:

http://%22.%24account_name.%22.domain.com

How can use this search result variable and redirect to the subdomain I am looking for?

  • 写回答

4条回答 默认 最新

  • drmlxgmqn18198265 2012-07-04 11:27
    关注

    You have syntax errors galore.

    Version 1 corrected (variables in single quotes are treated as literal strings):

    $username = //username taken from the db
    $url = 'http://".$username."domain.com';
    header('location: ' . $url);
    

    Version 2 corrected (Your syntax and quote usage are both wrong):

    header("Location: http://".$username."domain.com");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程