PDA

View Full Version : آموزش: تغییر مسیر امن در PHP



birtemp
چهارشنبه 10 خرداد 1391, 12:03 عصر
تغییر مسیر امن در PHP. از این قطعه کد در مکانهایی که می خواهید به یک صفحه غیر از صفحات وب سایت خود لینک بدهید، می توانید استفاده کنید. مزیت این کد در این می باشد که شما را به صورت امن (Http://www.Prolearn-vs.com) و بدون اینکه به سایت شما صدمه ای وارد شود، به لینک مورد نظر منتقل می کند.



function safe_redirect($url, $exit=true) {

// Only use the header redirection if headers are not already sent
if (!headers_sent()){

header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $url);

// Optional workaround for an IE bug (thanks Olav)
header("Connection: close");
}

// HTML/JS Fallback:
// If the header redirection did not work, try to use various methods other methods

print '<html>';
print '<head><title>Redirecting you...</title>';
print '&lt;meta <a title="آموزش حرفه ای برنامه نویسی" href="Http://www.Prolearn-vs.com" target="_blank">http-equiv</a>="Refresh" <a title="آموزش حرفه ای برنامه نویسی" href="Http://www.Prolearn-vs.com" target="_blank">content</a>="0;url='.$url.'" /&gt;';
print '&lt;/head&gt;';
print '&lt;body onload="location.replace(\''.$url.'\')"&gt;';

// If the javascript and meta redirect did not work,
// the user can still click this link
print 'You should be redirected to this URL:&lt;br /&gt;';
print "&lt;a href="$url"&gt;$url&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;";

print 'If you are not, please click on the link above.&lt;br /&gt;';

print '&lt;/body&gt;';
print '&lt;/html&gt;';

// Stop the script here (optional)
if ($exit) exit;
}