<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Returns the subject of a CSR</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-csr-get-public-key.html">openssl_csr_get_public_key</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.openssl-csr-new.html">openssl_csr_new</a></div> <div class="up"><a href="ref.openssl.html">OpenSSL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.openssl-csr-get-subject" class="refentry"> <div class="refnamediv"> <h1 class="refname">openssl_csr_get_subject</h1> <p class="verinfo">(PHP 5 >= 5.2.0, PHP 7)</p><p class="refpurpose"><span class="refname">openssl_csr_get_subject</span> — <span class="dc-title">Returns the subject of a CSR</span></p> </div> <div class="refsect1 description" id="refsect1-function.openssl-csr-get-subject-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>openssl_csr_get_subject</strong></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$csr</code></span> [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$use_shortnames</code><span class="initializer"> = <strong><code>TRUE</code></strong></span></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>openssl_csr_get_subject()</strong></span> returns subject distinguished name information encoded in the <code class="parameter">csr</code> including fields commonName (CN), organizationName (O), countryName (C) etc. </p> </div> <div class="refsect1 parameters" id="refsect1-function.openssl-csr-get-subject-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">csr</code></dt> <dd> <p class="para"> See <a href="openssl.certparams.html" class="link">CSR parameters</a> for a list of valid values. </p> </dd> <dt> <code class="parameter">use_shortnames</code></dt> <dd> <p class="para"> <code class="parameter">shortnames</code> controls how the data is indexed in the array - if <code class="parameter">shortnames</code> is <strong><code>TRUE</code></strong> (the default) then fields will be indexed with the short name form, otherwise, the long name form will be used - e.g.: CN is the shortname form of commonName. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.openssl-csr-get-subject-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.openssl-csr-get-subject-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-959"> <p><strong>Example #1 openssl_csr_get_subject() example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$subject </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">"countryName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"CA"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"stateOrProvinceName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Alberta"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"localityName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Calgary"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"organizationName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"XYZ Widgets Inc"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"organizationalUnitName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"PHP Documentation Team"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"commonName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Wez Furlong"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"emailAddress" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"wez@example.com"</span><span style="color: #007700">,<br />);<br /></span><span style="color: #0000BB">$private_key </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_pkey_new</span><span style="color: #007700">(array(<br /> </span><span style="color: #DD0000">"private_key_bits" </span><span style="color: #007700">=> </span><span style="color: #0000BB">2048</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"private_key_type" </span><span style="color: #007700">=> </span><span style="color: #0000BB">OPENSSL_KEYTYPE_RSA</span><span style="color: #007700">,<br />));<br /></span><span style="color: #0000BB">$configargs </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'digest_alg' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'sha512WithRSAEncryption'<br /></span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$csr </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_csr_new</span><span style="color: #007700">(</span><span style="color: #0000BB">$subject</span><span style="color: #007700">, </span><span style="color: #0000BB">$privkey</span><span style="color: #007700">, </span><span style="color: #0000BB">$configargs</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">openssl_csr_get_subject</span><span style="color: #007700">(</span><span style="color: #0000BB">$csr</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Array ( [C] => CA [ST] => Alberta [L] => Calgary [O] => XYZ Widgets Inc [OU] => PHP Documentation Team [CN] => Wez Furlong [emailAddress] => wez@example.com ) </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.openssl-csr-get-subject-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="function.openssl-csr-new.html" class="function" rel="rdfs-seeAlso">openssl_csr_new()</a> - Generates a CSR</span></li> <li class="member"><span class="function"><a href="function.openssl-csr-get-public-key.html" class="function" rel="rdfs-seeAlso">openssl_csr_get_public_key()</a> - Returns the public key of a CSR</span></li> <li class="member"><span class="function"><a href="function.openssl-x509-parse.html" class="function" rel="rdfs-seeAlso">openssl_x509_parse()</a> - Parse an X509 certificate and return the information as an array</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-csr-get-public-key.html">openssl_csr_get_public_key</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.openssl-csr-new.html">openssl_csr_new</a></div> <div class="up"><a href="ref.openssl.html">OpenSSL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>