Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP headers in redirect script do not work
    text
    copied!<p>I want the following code <code>header ('Location:'. $U);</code></p> <p>Rightly guided, but I'm getting the following warning, how to resolve it.</p> <pre><code>Warning: Cannot modify header information - headers already sent by (output started at H:\xampp\htdocs\redirected\index.php:8) in H:\xampp\htdocs\redirected\index.php on line 53 </code></pre> <p>i want :</p> <p><code>http://mydomian/google redirect to http://google.com</code></p> <p>or</p> <p><code>http://mydomian/yahoo redirect to http://yahoo.com</code></p> <p>or</p> <p><code>http://mydomian/anyname redirect to http://Every site that I like</code></p> <p>..............................</p> <p>my htacess file :</p> <pre><code>&lt;Files ~ "^\.(htaccess|htpasswd)$"&gt; deny from all &lt;/Files&gt; ErrorDocument 404 /redirected/index.php order deny,allow </code></pre> <p>in redirect folder i have files <strong>index.php</strong> and <strong>htaccess.txt</strong>:</p> <p>htaccess.txt : </p> <pre><code>/google http://google.com /yahoo http://yahoo.com </code></pre> <p>index.php:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;script for redirect !!!&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="&lt;?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?&gt;" method="post"&gt; &lt;input type="text" name="url" placeholder="e.g google.com" required/&gt; &lt;input type="text" name="dir" placeholder="dir" value=&lt;?php echo htmlspecialchars($_SERVER['REQUEST_URI']);?&gt; required/&gt; &lt;input type="submit" /&gt; &lt;/form&gt; &lt;?php $url = (isset($_POST['url'])) ? $_POST['url'] : ''; $dir = (isset($_POST['dir'])) ? $_POST['dir'] : ''; $filename = 'htaccess.txt'; /* * * Function to make URLs into links * * @param string The url string * * @return string * */ function makeLink($string){ /*** make sure there is an http:// on all URLs ***/ $string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string); /*** make all URLs links ***/ $string = preg_replace("/([\w]+:\/\/[\w-?&amp;;#~=\.\/\@]+[\w\/])/i","&lt;a target=\"_blank\" href=\"$1\"&gt;$1&lt;/A&gt;",$string); /*** make all emails hot links ***/ $string = preg_replace("/([\w-?&amp;;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","&lt;A HREF=\"mailto:$1\"&gt;$1&lt;/A&gt;",$string); return $string; } function redirect($url){ if (headers_sent()) { die('&lt;script type="text/javascript"&gt;window.location.href="' . $url . '";&lt;/script&gt;'); }else { header('Location: ' . $url); die(); } } $f = !empty($dir) ? $dir: htmlspecialchars($_SERVER['REQUEST_URI']); $fp = fopen($filename , 'r+') or die("can't open file ! "); while ( !feof( $fp ) ) { $line = fgets( $fp, 1024 ); if ($f === strstr($line, ' ', true)) { $u = strstr($line, 'http'); //redirect($u); //echo '&lt;script type="text/javascript"&gt;window.location.href="' . $u . '";&lt;/script&gt;'; header('Location: ' . $u); exit; } } if ($url != '' &amp;&amp; !empty($dir)) { fseek($fp, 0, SEEK_END); // Go to the end of the file fwrite($fp,"/$dir http://$url \n"); fclose($fp); } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload