Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do Stack Overflow URLs work?
    text
    copied!<p>I have build URLs of my site like Stack&nbsp;Overflow URLs. My URLs are as below.</p> <pre><code>http://www.example.com/1255544/this-is-the-url-text </code></pre> <p>In this URL, <code>1255544</code> is the id and <code>this-is-the-url-text</code> is the URL title text, both stored in the database. I have noticed that Stack&nbsp;Overflow URLs work on the base of id. Suppose here is a Stack&nbsp;Overflow URL</p> <pre><code>http://stackoverflow.com/questions/15679171/new-way-to-prevent-xss-attacks </code></pre> <p>In this URL, <code>15679171</code> is the id of the post. When I changed this id to <code>15706581</code> without touching the <code>new-way-to-prevent-xss-attacks</code> and pressed Enter, the URL automatically changed to the following URL:</p> <pre><code>http://stackoverflow.com/questions/15706581/simplecursoradapter-does-not-load- external-sqlite-database-id-error </code></pre> <p>And when I tried to remove some of the part of the URL title text like below</p> <pre><code>http://stackoverflow.com/questions/15679171/new-way-to-preve </code></pre> <p>It automatically corrects the URL as below:</p> <pre><code>http://stackoverflow.com/questions/15679171/new-way-to-prevent-xss-attacks </code></pre> <p>It means the data is being retrieved from the database on the basis of id <code>15679171</code> and the relevant URL title text, <code>new-way-to-prevent-xss-attacks</code>, is attached according to the id.</p> <p>I also want to do this. But the problem is, I am not going to understand that if someone change the id of the URL the title text should automatically changed. How do I do this?</p> <p>I have thought the following:</p> <pre><code>$url_id = $_GET["id"]; $url_txt = $_GET["url_txt"]; $qry = "SELECT * FROM mytable WHERE url_id = '{$url_id}' LIMIT 1"; $data = mysql_query($qry); $data_set = mysql_fetch_array($data); if($url_txt== $data_set["url_txt"]) { // proceed further } else { $rebuilt_url = "http://www.example.com/" . $url_id . "/" . $data_set["url_txt"]; header("Location: {$rebuilt_url}") // Redirect to this URL } </code></pre> <p>Is it the proper and efficient way to perform this action or not? Is there a solution?</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