/    Sign up×
Community /Pin to ProfileBookmark

PHP Site search Script (Null any JS or HTML loaded in Search bar)

I’m building a site right now and am wondering how to edit my php code for my site search so that it doesn’t allow any JS or HTML for security purposes. I have the code listed below and was wondering how you would go about coding this. Also feel free to include any pointers or tips….Thank you.

<form action=”<?php echo home_url(); ?>/” method=”get” id=”searchform”>
<fieldset>
<div id=”searchbox”>
<input class=”input” name=”s” type=”text” id=”keywords” value=”<?php _e(‘to search, type and hit enter’,’cosmotheme’) ?>” onfocus=”if (this.value == ‘<?php _e(‘to search, type and hit enter’,’cosmotheme’) ?>’) {this.value = ”;}” onblur=”if (this.value == ”) {this.value = ‘<?php _e(‘to search, type and hit enter’,’cosmotheme’) ?>’;}”>
</div>
<p class=”button hover square”>
<input type=”submit” name=”search” value=”<?php _
e(‘Search’,’cosmotheme’) ?>”>
</p>
</fieldset>
</form>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ericatekkaJan 25.2012 — Yep. On the search PHP page, before you do any processing, use something like the following.

[code=php]<?php
//declare variable
$VARIABLE = $_GET['s'];
//strips tags of any HTML
$VARIABLE = strip_tags($VARIABLE);
//If you have < 5.3(or 5.2?) you can use PCRE expressions to sanitize any input that will interact with the DB.
$VARIABLE = filter_var($_GET['s'], FILTER_SANITIZE_STRING);
?>[/code]
Copy linkTweet thisAlerts:
@amorteauthorJan 25.2012 — Thank you very much! WEBDEV is a great place to seek help! ?
×

Success!

Help @amorte spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...