简体   繁体   English

如何获取网址段?

[英]how can I get a url segment?

I have the last url segment of the following url 我有以下网址的最后一个网址段

http://something.com/somefunc/10 http://something.com/somefunc/10

that is the number 10; 那是数字10;

My real problem is that I have a form that I need to post an action of the url 我的真正问题是我有一个需要张贴网址操作的表格

<form action="../something/somefunc/<?php echo $id>">
   //some code
</form>

after receiving the posted stuff, I would like to still be able to get the id of the product under consideration. 收到发布的内容后,我仍然希望能够获得正在考虑的产品ID。 I think now that form's action url is the only way I know that can help retain such an id. 我认为现在,表单的操作网址是我知道可以帮助保留此类ID的唯一方法。 Any help is appreciated, thank you. 任何帮助表示赞赏,谢谢。

[ UPDATE ] [ 更新 ]

Uhmmm, all the answers below are correct, don't know which one to choose as the best reply. 嗯,以下所有答案都是正确的,不知道该选择哪一个作为最佳答案。

Something along these lines may work... 遵循这些思路可能会起作用...

$url = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$parts = parse_url($url);
$path = $parts['path'];
$keys = explode('/', $path);
echo $keys[4]; // `corresponding to the 4th url word`

Hope this helps! 希望这可以帮助!

Sorry if I'm misunderstanding, but can't you get the ID of your posted form via the $_POST array? 抱歉,如果我误会了,但是您不能通过$ _POST数组获取已发布表单的ID吗? http://www.w3schools.com/php/php_post.asp http://www.w3schools.com/php/php_post.asp

Alternately, if the ID is in a URL parameter, you can access it via the $_GET variable: http://www.w3schools.com/php/php_get.asp 或者,如果ID在URL参数中,则可以通过$ _GET变量进行访问: http : //www.w3schools.com/php/php_get.asp

您可以使用ID输入隐藏的输入

<input type="hidden" name="id" value="<?php echo $id; ?>">

1.You could pass the product id using POST as a hidden input in your form: 1.您可以使用POST作为表单中的隐藏输入来传递产品ID:

<input name="productid" id="productid" type="hidden" value="<?=$id ?>">

and in the page you post to: 并在页面中发布到:

<? if (isset($_POST['productid'])) $id = $_POST['productid'] ?>

2.Alternatively use GET & pass it on the querystring 2.或者使用GET并将其传递给querystring

action="../something/somefunc/[processingpage]?productid=<?=$id ?>"

and in [processingpage]: 在[处理页面]中:

<? if (isset($_GET['productid'])) $id = $_GET['productid'] ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM