<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1044083" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1044083</link>
    <description></description>
    <language>en</language>
          <item>
    <title>Are you having problems with</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/get-variable#comment-1242412</link>
    <description> &lt;p&gt;Are you having problems with it? Errors? Or just wanting to know best procedure?&lt;/p&gt;
&lt;p&gt;At a &quot;quick&quot; glance it looks ok for functionality, but doesn&#039;t have any security or validation checking.&lt;/p&gt;
&lt;p&gt;You DO need a minimum of &lt;strong&gt;mysql_real_escape_string()&lt;/strong&gt; before using any vars on a query:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$username &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_real_escape_string&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//&amp;lt;-- This before the following query&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$sql &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;select * from users where username = &#039;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039; &quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;And if names are only EVER alphanumeric you could perhaps check this too:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;ereg&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;[^a-zA-Z0-9]&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)) {&lt;br /&gt;exit(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;Bad username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
That checks if the string ($username) has anything in it other than alphanumeric. The exit() will halt the script and output the text.&lt;br /&gt;
You likely want to do something other than exit, but certainly if the data is not what you expected then DON&#039;T run the QUERY.&lt;/p&gt;
&lt;p&gt;Even if it&#039;s not publicly available, you might one day enter bad data yourself, bad data/error on the first page (etc).&lt;/p&gt;
&lt;p&gt;That wont exit if the string ($username) is empty/null, so you probably want to check for that as well and output a different response, and again, don&#039;t run the query if empty.&lt;/p&gt;
&lt;p&gt;Also, is this publicly available?&lt;/p&gt;
 </description>
     <pubDate>Fri, 05 Jun 2009 18:01:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1242412 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>On firstpage.php, everything</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/get-variable#comment-1242408</link>
    <description> &lt;p&gt;On firstpage.php, everything looks ok. But depending on what you allow for a username, you may want to &lt;a href=&quot;http://us.php.net/urlencode&quot;&gt;urlencode&lt;/a&gt; the username inside the a tag. For example:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;printf&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;a href=&#039;secondpage.php?username=%s&#039;&amp;gt;%s&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;lt;br/&amp;gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;urlencode&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]),&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
If your username had an =, &amp;amp;, or other special characters, it might screw something up. &lt;/p&gt;
&lt;p&gt;On your secondpage.php, you would need to decode the username (that you previously encoded). But you also have a &lt;a href=&quot;http://en.wikipedia.org/wiki/SQL_injection&quot;&gt;SQL injection&lt;/a&gt; vulnerability. You need to sanitize your input using &lt;a href=&quot;http://us.php.net/mysql_real_escape_string&quot;&gt;mysql_real_escape_string()&lt;/a&gt; before passing parameters into a query. But you can&#039;t use it until your have a connection to the database setup, so you need to reorder your code:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// Connects to the database - must do this before calling mysql_real_escape_string()&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$con &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_connect&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;localhost&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;blank&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;blank&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) or die (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_error&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;());&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$db &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_select_db&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;wsdatabase&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) or die (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_error&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;());&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// Grabs the username with the get method.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if(isset(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_GET&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;])) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;urldecode&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_GET&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_real_escape_string&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// escape dangerous characters&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
 </description>
     <pubDate>Fri, 05 Jun 2009 17:39:00 +0000</pubDate>
 <dc:creator>teammatt3</dc:creator>
 <guid isPermaLink="false">comment 1242408 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
