Php 获取URL参数不起作用
我尝试从此url获取2个url参数: 使用下面的Php 获取URL参数不起作用,php,get,url-parameters,Php,Get,Url Parameters,我尝试从此url获取2个url参数: 使用下面的$\u GET和$\u REQUEST方法: $objektid = $_GET['id']; $stadt = $_GET['stadt']; 现在我得到了以下错误: Notice: Undefined index: id in /mnt/webb/a2/87/53907487/htdocs/flyingchange/src/checkout.php on line 10 Notice: Undefined index: stadt in
$\u GET
和$\u REQUEST
方法:
$objektid = $_GET['id'];
$stadt = $_GET['stadt'];
现在我得到了以下错误:
Notice: Undefined index: id in /mnt/webb/a2/87/53907487/htdocs/flyingchange/src/checkout.php on line 10
Notice: Undefined index: stadt in /mnt/webb/a2/87/53907487/htdocs/flyingchange/src/checkout.php on line 11
我对php相当陌生,因此我非常感谢您在这方面的帮助。我自己找不到错误。您的页面具有html扩展名。所以有一个错误,只有带有php扩展的页面才使用php进行分析。。。您必须将URL重写为detail.php,并将扩展名更改为php。希望有帮助:) 更新: 在这种情况下,您需要:
/flyingchange/detail.php?id=gXpzX09kyF&stadt=Regensburg&Checkout=true
和detail.php:
<?php
$stadt = isset($_GET['stadt']) ? $_GET['stadt'] : 'default_stadt';
$id = isset($_GET['id']) ? $_GET['id'] : 'default_id';
print_r($id);
echo '<br>';
print_r($stadt);
?>
还请记住,在您使用localhost之前,请确保您的链接指向localhost上的地址…:) 这些不是实际的错误。它们只是通知。您收到这些通知是因为最初没有为它们指定值。抑制这些通知的快速修复方法是使用静音操作符。见下文:
$objektid = @$_GET['id'];
$stadt = @$_GET['stadt'];
我刚换了分机,又试了一次,但同样的错误也许这有帮助?您的页面根目录是哪个目录?您正在使用localhost吗?谢谢您的尝试,但我已经在服务器上执行了它。Hayder Abbass的答案对我来说是可行的。你能写下为什么这不起作用吗
@
不是一个优雅的解决方案。我建议使用类似的方法:$stadt=isset($\u GET['stadt'])$_获取['statt']:'default_statt'代码>@
符号太不优雅了:)。谢谢,这已经解决了;)我会在5分钟内接受这个答案