summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2008-04-27 15:35:20 +0200
committerDerek Allard <derek.allard@ellislab.com>2008-04-27 15:35:20 +0200
commit05f830c7105ef3cd4a8388bffe7cf73c35236105 (patch)
treec8cf4ac58531db10ff7606ae8f2eea29a092b779
parentf9d5348cf2776374bf09bdda8c941198167d9ae9 (diff)
Added the ability to include an optional HTTP Response Code in the redirect() function of the URL Helper.
-rw-r--r--system/helpers/url_helper.php6
-rw-r--r--user_guide/changelog.html1
-rw-r--r--user_guide/helpers/url_helper.html13
3 files changed, 13 insertions, 7 deletions
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index bd94b390c..1ff26082c 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -470,6 +470,8 @@ if (! function_exists('url_title'))
* Header Redirect
*
* Header redirect in two flavors
+ * For very fine grained control over headers, you could use the Output
+ * Library's set_header() function.
*
* @access public
* @param string the URL
@@ -478,13 +480,13 @@ if (! function_exists('url_title'))
*/
if (! function_exists('redirect'))
{
- function redirect($uri = '', $method = 'location')
+ function redirect($uri = '', $method = 'location', $http_response_code = 302)
{
switch($method)
{
case 'refresh' : header("Refresh:0;url=".site_url($uri));
break;
- default : header("Location: ".site_url($uri));
+ default : header("Location: ".site_url($uri), TRUE, $http_response_code);
break;
}
exit;
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 6ed2a2185..767dd2a48 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -88,6 +88,7 @@ SVN Commit: not currently released</p>
<li>Helpers
<ul>
<li>Added <kbd>form_button()</kbd> in the <a href="helpers/form_helper.html">Form helper</a>.</li>
+ <li>Added the ability to include an optional HTTP Response Code in the <kbd>redirect()</kbd> function of the <a href="helpers/url_helper.html">URL Helper</a>.</li>
<li>Modified <kbd>img()</kbd> in the <a href="helpers/html_helper.html">HTML Helper</a> to remove an unneeded space (#4208).</li>
<li>Modified <kbd>anchor()</kbd> in the <a href="helpers/url_helper.html">URL helper</a> to convert entities in the title attribute (#4209).</li>
<li>The <a href="helpers/download_helper.html">Download helper</a> now exits within <kbd>force_download()</kbd>.</li>
diff --git a/user_guide/helpers/url_helper.html b/user_guide/helpers/url_helper.html
index 3efb7ed5f..7bda86da9 100644
--- a/user_guide/helpers/url_helper.html
+++ b/user_guide/helpers/url_helper.html
@@ -18,7 +18,6 @@
<meta name='robots' content='all' />
<meta name='author' content='ExpressionEngine Dev Team' />
<meta name='description' content='CodeIgniter User Guide' />
-
</head>
<body>
@@ -231,16 +230,20 @@ $url = prep_url($url);</code>
to redirect to a local URL within your site. You will <strong>not</strong> specify the full site URL, but rather simply the URI segments
to the controller you want to direct to. The function will build the URL based on your config file values.</p>
-<p>The second parameter allows you to choose between the "location"
-method (default) or the "refresh" method. Location is faster, but on Windows servers it can sometimes be a problem. Example:</p>
+<p>The optional second parameter allows you to choose between the "location"
+method (default) or the "refresh" method. Location is faster, but on Windows servers it can sometimes be a problem. The optional third parameter allows you to send a specific HTTP Response Code - this could be used for example to create 301 redirects for search engine purposes. The default Response Code is 302. The third parameter is <em>only</em> available with 'location' redirects, and not 'refresh'. Examples:</p>
<code>if ($logged_in == FALSE)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect('/login/form/', 'refresh');<br />
-}</code>
+}<br />
+<br />
+// with 301 redirect<br />
+redirect('/article/13', 'location', 301);</code>
<p class="important"><strong>Note:</strong> In order for this function to work it must be used before anything is outputted
-to the browser since it utilizes server headers.</p>
+to the browser since it utilizes server headers.<br />
+<strong>Note:</strong> For very fine grained control over headers, you should use the <a href="../libraries/output.html">Output Library</a>'s set_header() function.</p>