tag:blogger.com,1999:blog-10890522089573804612024-03-08T09:02:59.863-08:00PHP.netLittleOnehttp://www.blogger.com/profile/16995593011908831757noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-1089052208957380461.post-58757043184230819862011-06-27T08:16:00.001-07:002011-06-27T08:16:59.189-07:00Functions for preventing both SQL and XSS injection attacks<p>Functions for preventing both SQL and XSS injection attacks <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 470px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff"><?</span>php<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/function">function</a> mysql_entities_fix_string($string)<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">{<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <a style="color: #0000ff" href="http://www.php.net/return">return</a> <a style="color: #ffa500" href="http://www.php.net/htmlentities">htmlentities</a>(mysql_fix_string($string));<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">}<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/function">function</a> mysql_fix_string($string)<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">{<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <a style="color: #0000ff" href="http://www.php.net/if">if</a> (<a style="color: #ffa500" href="http://www.php.net/get_magic_quotes_gpc">get_magic_quotes_gpc</a>()) $string = <a style="color: #ffa500" href="http://www.php.net/stripslashes">stripslashes</a>($string);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <a style="color: #0000ff" href="http://www.php.net/return">return</a> mysql_real_escape_string($string);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">}<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">?></span></pre></pre></p> LittleOnehttp://www.blogger.com/profile/16995593011908831757noreply@blogger.com0tag:blogger.com,1999:blog-1089052208957380461.post-20612728502186386132011-06-27T08:09:00.001-07:002011-06-27T08:09:53.585-07:00Using placeholders with PHP<p>Once you have prepared a statement, until you deallocate it, you can use it as often as you wish. Such statements are commonly used within a loop to quickly insert data into a database by assigning values to the MySQL variables and then executing the state-ment. This approach is more efficient than creating the entire statement from scratch on each pass through the loop.</p> <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 510px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff"><?</span>php<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/require">require</a> '<span style="color: #8b0000">login.php</span>';<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">$db_server = <a style="color: #ffa500" href="http://www.php.net/mysql_connect">mysql_connect</a>($db_hostname, $db_username, $db_password);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/if">if</a> (!$db_server) <a style="color: #0000ff" href="http://www.php.net/die">die</a>("<span style="color: #8b0000">Unable to connect to MySQL: </span>" . <a style="color: #ffa500" href="http://www.php.net/mysql_error">mysql_error</a>());<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/mysql_select_db">mysql_select_db</a>($db_database)<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> or <a style="color: #0000ff" href="http://www.php.net/die">die</a>("<span style="color: #8b0000">Unable to select database: </span>" . <a style="color: #ffa500" href="http://www.php.net/mysql_error">mysql_error</a>());<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">$query = '<span style="color: #8b0000">PREPARE statement FROM "INSERT INTO classics<br /></span></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> VALUES(?,?,?,?,?)"<span style="color: #8b0000">';<br /></span></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/mysql_query">mysql_query</a>($query);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">$query = '<span style="color: #8b0000">SET @author = "Emily Brontë",</span>' .<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> '<span style="color: #8b0000">@title = "Wuthering Heights",</span>' .<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> '<span style="color: #8b0000">@category = "Classic Fiction",</span>' .<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> '<span style="color: #8b0000">@year = "1847",</span>' .<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> '<span style="color: #8b0000">@isbn = "9780553212587"</span>';<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/mysql_query">mysql_query</a>($query);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">$query = '<span style="color: #8b0000">EXECUTE statement USING @author,@title,@category,@year,@isbn</span>';<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/mysql_query">mysql_query</a>($query);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">$query = '<span style="color: #8b0000">DEALLOCATE PREPARE statement</span>';<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/mysql_query">mysql_query</a>($query);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">?></span></pre></pre> LittleOnehttp://www.blogger.com/profile/16995593011908831757noreply@blogger.com0tag:blogger.com,1999:blog-1089052208957380461.post-72703548403478973572011-06-27T08:02:00.001-07:002011-06-27T08:04:43.801-07:00How to properly sanitize user input for MySQL<p>  <br />The get_magic_quotes_gpc function returns TRUE if magic quotes are active. In that case,any slashes that have been added to a string have to be removed or the function mysql_real_eascape_string could end up double-escaping some characters, creating corrupted strings. <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff"><?</span>php<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/function">function</a> mysql_fix_string($string)<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">{<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <a style="color: #0000ff" href="http://www.php.net/if">if</a> (<a style="color: #ffa500" href="http://www.php.net/get_magic_quotes_gpc">get_magic_quotes_gpc</a>()) $string = <a style="color: #ffa500" href="http://www.php.net/stripslashes">stripslashes</a>($string);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <a style="color: #0000ff" href="http://www.php.net/return">return</a> mysql_real_escape_string($string);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">}<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">?></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre></pre></p> LittleOnehttp://www.blogger.com/profile/16995593011908831757noreply@blogger.com0tag:blogger.com,1999:blog-1089052208957380461.post-40292738062417311402011-05-12T12:39:00.000-07:002011-05-13T13:52:59.008-07:00Problem with WAMP Server<p>I have developed many sites with PHP with WAMP Server.So I thought I had some experience in WAMP.But after installing new WAMP Server I doubt about that.Because it was always offline.WAMP icon shows yellow it means some working but not all.Actually I could use MySQL but not PHP.I tried MySQL by left click Wamp icon->MySQL –>MySQL console it works.I search many blogs and most of says it might be due to Skype or IIS server but I didn’t have installed IIS and I checked by uninstalling Skype,still I got offline color.</p> <p>Then I tried to stop some other related services in Control Panel\All Control Panel Items\Administrative Tools\Services or you can get that window  by right click MyComputer icon –>manage->Services and Application->Services if you are an administrator of that machine you can start or stop services on that list.But it doesn’t work for me.</p> <p>I searched it again.Then I found one video with editing some code but it’s boring and so long to edit so I kept that away.after I found a article how to do that simply.just go to WAMP icon & left click->apache->services->test port 80  then I found “your port 80 is actually used by server microsoft-httpapi 2.0” so I found at last it was taken by some other process.So I did change the port no 80 to 81 it works for me.you can edit that one from editing httpd.conf in  WAMP icon & left click->apache->httpd.conf search listen 80 and edit that to 81.</p> LittleOnehttp://www.blogger.com/profile/16995593011908831757noreply@blogger.com0tag:blogger.com,1999:blog-1089052208957380461.post-8054900204921017252011-01-31T11:02:00.001-08:002011-01-31T12:12:06.670-08:00Insert A Web Page to an another Page<p></p> <div>Hi all after very a long time.I thought to stop this blog due to lack of motivation<img style="border-right: 0px; border-top: 0px; margin: 0px; border-left: 0px; border-bottom: 0px" height="15" alt="" src="http://em.xjoy.org/i/bubble48.gif" width="15" border="0" /> . But  I’m back Now <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="15" alt="" src="http://em.xjoy.org/i/bubble0.gif" width="15" border="0" /> .</div> <div>I got the idea to post this from the one of my friend. He wanted to know how to insert a web page into an another  using PHP.You have to do is simply add an include tag <strong>inside the body tag</strong>.This method is useful when creating a php templates.In following example include php code are placed inside the div tags.You can also place this inside the table and other tags inside the body tag.</div> <div> </div> <div> <pre id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 73.84%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 208px; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><html><br /> <body><br /> <div><br /> <?php <span style="color: #0000ff">include</span>(<span style="color: #006080">"header.php"</span>); ?><br /> </div><br /> <div><br /> <?php <span style="color: #0000ff">include</span>(<span style="color: #006080">"body.php"</span>); ?><br /> </div><br /> <div><br /> <?php <span style="color: #0000ff">include</span>(<span style="color: #006080">"footer.php"</span>); ?><br /> </div> <br /> </body><br /></html><br /></pre><br /></div><br /><br /><div><a href="http://lh3.ggpht.com/_xqsMTcQqfRs/TUcMQMkv2TI/AAAAAAAAAE0/RC7NsF1NLXw/s1600-h/image%5B2%5D.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="84" alt="image" src="http://lh5.ggpht.com/_xqsMTcQqfRs/TUcMQyNqIxI/AAAAAAAAAE4/zKME1gkwSCI/image_thumb.png?imgmax=800" width="244" border="0" /></a> </div><br /><br /><div>Hope you got something  if you are not familiar about this.</div><br /><br /><div>Until next post cheers <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="16" alt="" src="http://em.xjoy.org/i/bubble47.gif" width="16" border="0" /> </div> LittleOnehttp://www.blogger.com/profile/16995593011908831757noreply@blogger.com0tag:blogger.com,1999:blog-1089052208957380461.post-69599116929640316342009-08-29T07:07:00.001-07:002009-08-29T07:07:20.596-07:00What Is a Session?<p>A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.</p> <p>There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.</p> <p>Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.</p> LittleOnehttp://www.blogger.com/profile/16995593011908831757noreply@blogger.com0tag:blogger.com,1999:blog-1089052208957380461.post-18134763328527934342009-07-30T03:52:00.001-07:002009-08-29T07:01:39.790-07:00What is PHP<p><b>PHP</b> is a scripting language which originally  was stood for Personal Home Page by Rasmus Lerdorf(1994)</p> <p><a href="http://en.wikipedia.org/wiki/File:Rasmus_Lerdorf_cropped.jpg"><img alt="" src="http://upload.wikimedia.org/wikipedia/commons/thumb/9/9c/Rasmus_Lerdorf_cropped.jpg/100px-Rasmus_Lerdorf_cropped.jpg" width="100" height="135" /></a></p> <p>after modifications by Andi Gutmans and Zeev Suraski(1997)</p> <p> <a href="http://en.wikipedia.org/wiki/File:Andi_Gutmans_1.jpg"><img alt="" src="http://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Andi_Gutmans_1.jpg/100px-Andi_Gutmans_1.jpg" width="100" height="135" /></a><a href="http://en.wikipedia.org/wiki/File:Zeev_Suraski_2005_cropped.jpg"><img alt="" src="http://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Zeev_Suraski_2005_cropped.jpg/100px-Zeev_Suraski_2005_cropped.jpg" width="100" height="135" /></a></p> <p>it changed to PHP: hypertext  preprocessor.It is free software .</p><br />The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.LittleOnehttp://www.blogger.com/profile/16995593011908831757noreply@blogger.com0