PHP localhost配置假域名访问项目,拒绝调试时$_SERVER['HTTP_HOST']抓不到域名

本文介绍如何通过配置本地假域名解决从SVN拉取项目后出现的域名抓取失败及控制器找不到等问题,包括修改hosts文件及使用phpstudy进行站点域名管理的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上线的项目用svn拉下来后经常在比方登陆注册啊,抓不到域名找不到控制器,在本地配一个假域名即可解决。

第一步:

1.找到记事本,右击,管理员身份运行


2.打开后,文件,打开c/Windows/System32/drivers/etc/hosts


3.添加假域名


第二步:

1.在phpstudy点击其他选项,点击站点域名管理


2.添加假域名,项目根目录,点击新增,ok了惊讶





<?php // login_process.php session_start(); // 开启错误报告 error_reporting(E_ALL); ini_set('display_errors', 1); // 连接数据库 $conn =mysqli_connect('localhost','root','131415','san'); if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } // 获取用户输入 $user_type = $_POST['user_type']; $id = $_POST['id']; $input_pass =$_POST['password']; // 注意:md5 不安全,建议使用 password_hash() // 根据用户类型构建 SQL 查询 if ($user_type == 'student') { $sql = "SELECT * FROM student WHERE id = ? AND password = ?"; } else { $sql = "SELECT * FROM teacher WHERE id = ? AND password = ?"; } // 使用预处理语句防止 SQL 注入 $stmt = $conn->prepare($sql); if (!$stmt) { die("预处理失败: " . $conn->error); } // 绑定参数 $stmt->bind_param("ss", $id, $input_pass); // 执行查询 if (!$stmt->execute()) { die("查询执行失败: " . $stmt->error); } // 获取结果 $result = $stmt->get_result(); // 检查是否有匹配的用户 if ($result->num_rows > 0) { $user = $result->fetch_assoc(); $_SESSION['user_id'] = $id; $_SESSION['user_type'] = $user_type; $_SESSION['name'] = $user[$user_type == 'student' ? 's_name' : 't_name']; // 根据用户类型跳转 if ($user_type == 'teacher') { $_SESSION['is_admin'] = $user['is_admin']; header("Location: " . ($user['is_admin'] ? 'admin.php' : 'teacher.php')); } else { header("Location: student.php"); } exit(); // 确保跳转后脚本终止 } else { echo "登录失败! 用户名或密码错误。 <a href='login.php'>重试</a>"; } // 关闭连接 $stmt->close(); $conn->close(); ?>提示第12行和43行错误
03-21
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; if ($request_uri !~* "/wx_api/") { return 403; } location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } 帮我看一下为什么使用http://localhost/wx_api/访问返回404
最新发布
07-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值