这是在PHP中使用get的正确方法吗?

I'm using the below for get in php without a form.

If($q)
{
header("location:d.php?q=$name");
}

Is it correct?

According to the specification, the URI in the location header must be an absolute URI.

But regardless of this, your code will create an (unnecessary?) redirect.

If you want to persist values between requests, a better way would to use sessions.

Although relative ones usually work, the URL specified by location: must be an absolute URL.

Other than that, we don't know what you are doing of course, but it's an okay header redirect to another address. If $name contains something, it will be sent to that URL as a query parameter.