How to get id from url php pages?

Good time of day.
I have a website with articles where the url is passed the id of the article.
As these articles have comments.
The functionality of adding a comment via a php form action. In this page action fails to give me the id of the article.

Here is the code:
<form action="ajax/comment_captcha_verify.php" method="post">
 <?php if(!empty($_SESSION['login'])):?>
 <label for="username">Your username:</label>
 <input type="text" readonly name="username" value="<?=$_SESSION['login']?>" id="username" class="form-control">

 <label for="mess">Message:</label>
 <textarea name="mess" id="mess" class="form-control" placeholder="Enter comment"></textarea>

 <!-- captcha -->
 <div class="g-recaptcha mt-3" data-sitekey="6LcsHucUAAAAAFq4qZqiDNYgcql3xAPFtpzvjxhh"></div>
<br / >
 <button id="mess_send" name="mess_send" class="btn btn-success mb-5">Add comment</button>
 <div class="alert alert-danger" id="errorBlock"></div>
 <?php else: ?>
 <div class="alert alert-primary" role="alert">
 Log in to leave comments
</div>
 <?php endif;?>
 </form>


Other pages get article id, using $_GET['id'], but there is another does not work.

That is, it is impossible to redirect and add a comment to a specific article.
header("Location: /news.php?id={$_GET['id']}"); - this code does not work in action
April 19th 20 at 12:19
1 answer
April 19th 20 at 12:21
Solution
Decided very easy.

I just finished writing in the form of:
<input type="hidden" name="article_id" value="<?=$_GET['id'];?>">


Then I gave that article_id to the page, where the logic:
$article_id = $_POST['article_id'];

And now I have the option id with the url of the first page ;)
as to the action to add strength is not enough? - deborah.Huels commented on April 19th 20 at 12:24
@deborah.Huels, most likely the knowledge, because no experience was not with this task. This is only the first experience. And it is not studied anywhere else. Purely for practice go. Learn only what I need at this point. That is, learning during practice, and thank You all! - Mitchel_Willms commented on April 19th 20 at 12:27
@deborah.Huels, And by the way, using action to implement?
Show me an example with your code, please.
It's very important to know, because if You say it, then this option is definitely better - Mitchel_Willms commented on April 19th 20 at 12:30
well, what if all the knowledge by analogy is
here you have /news.php?id=666
and here you have ajax/comment_captcha_verify.php
and there's the url, there url
is transmitted in the first ID
if you need to pass in the second, then append to it the same

Only the variable is displayed differently.
But as a variable in the HTML output you have in the code ALSO have -
it is possible to make by analogy. - deborah.Huels commented on April 19th 20 at 12:33
@deborah.Huels, I'll try it now, thank you. I'm just not smart enough, or just didn't know that action is transmitted even url. But that time failed, using $_GET['id'] - Mitchel_Willms commented on April 19th 20 at 12:36
@deborah.Huels, so you mean that first page to start a session $_GET['id']?
Because otherwise it does not work, then there is another page on the id of the article. It turned out only through the input - Mitchel_Willms commented on April 19th 20 at 12:39
so what does session.
this is an example of output

a variable can be anything - session, get, post any variable. - deborah.Huels commented on April 19th 20 at 12:42
@deborah.Huels, I like what you said and did. Why do you say hints. Tell the difference, but I do not understand what's the difference - Mitchel_Willms commented on April 19th 20 at 12:45

Find more questions by tags MySQLPHP