qwe010 Posted September 15, 2006 Share Posted September 15, 2006 hi allplease how i can secure this code[code]if(!isset($_GET['page'])){ $page = 1; } else {$page = intval( $_GET['page'] );}[/code]if i do that index.php?page='You have an error in your SQL syntaxany idea ? Quote Link to comment https://forums.phpfreaks.com/topic/20896-how-i-can-secure-this-code/ Share on other sites More sharing options...
Wintergreen Posted September 15, 2006 Share Posted September 15, 2006 php.net seems to be down right now, but the function you can use to check and see if it is numeric is is_numeric() Quote Link to comment https://forums.phpfreaks.com/topic/20896-how-i-can-secure-this-code/#findComment-92583 Share on other sites More sharing options...
qwe010 Posted September 16, 2006 Author Share Posted September 16, 2006 i try itbut i don't know how i do it with is_numeric()i think i can but intval with[quote]if(!isset($_GET['page'])){ $page = 1;[/quote] but how ? Quote Link to comment https://forums.phpfreaks.com/topic/20896-how-i-can-secure-this-code/#findComment-92949 Share on other sites More sharing options...
redarrow Posted September 16, 2006 Share Posted September 16, 2006 you have a link with a condition and then get what you want example onlylink example with condition.[code]<?phpecho"<a href='mypage.php?page=$page&cmd=condition_set'>go to my page</a>?>[/code]then this on the other page.[code]<?php session_start();//the condition of the link must match.if($_GET['cmd']=="condition_set"){$page=$_GET['page'];}else{//the condition of the link did not match.echo"sorry who are you man?";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20896-how-i-can-secure-this-code/#findComment-93010 Share on other sites More sharing options...
448191 Posted September 16, 2006 Share Posted September 16, 2006 There is no need to use intval on numeric stings, unless you want a copy that has the equivalant integer value.[code]<?phpif(!isset($_GET['page']) || empty($_GET['page'])){ $page = 1;} else { }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20896-how-i-can-secure-this-code/#findComment-93013 Share on other sites More sharing options...
qwe010 Posted September 16, 2006 Author Share Posted September 16, 2006 if i do it like that [quote]if(!isset($_GET['page']) == empty($_GET['page'])){ $page = 1; } else {$page = intval( $_GET['page'] );}[/quote]and do thatindex.php?page='all thing okbut if i do it like thatindex.php?page=You have an error in your SQL syntaxhow i fix that ?and my program isShows the news like thatindex.php?page=1news 1index.php?page=2news 2 Quote Link to comment https://forums.phpfreaks.com/topic/20896-how-i-can-secure-this-code/#findComment-93031 Share on other sites More sharing options...
wildteen88 Posted September 16, 2006 Share Posted September 16, 2006 Use this:[code=php:0]// chekc that page is srt and that it holds a numerical valueif(isset($_GET['page']) && is_numeric($_GET['page'])){ $page = $_GET['page'];}else{ $page = 1;}[/code]If your url is index.php?page= or index.php?page=' or someothing else that is non numeric it will set $page to 1. if your url is this: index.php?page=1 or index.php?page=somenumberhere (eg index.php?page=99) it'll set $page to $_GET['page']This is more secure than what you have now. Quote Link to comment https://forums.phpfreaks.com/topic/20896-how-i-can-secure-this-code/#findComment-93033 Share on other sites More sharing options...
448191 Posted September 16, 2006 Share Posted September 16, 2006 Lol, I thought the quote was a typo.. ;D Quote Link to comment https://forums.phpfreaks.com/topic/20896-how-i-can-secure-this-code/#findComment-93042 Share on other sites More sharing options...
qwe010 Posted September 16, 2006 Author Share Posted September 16, 2006 Thanks wildteen88 :) It is works ok Quote Link to comment https://forums.phpfreaks.com/topic/20896-how-i-can-secure-this-code/#findComment-93084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.