Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-08-2009, 07:04 AM   PM User | #1
Blatch
New Coder

 
Join Date: Mar 2003
Location: USA
Posts: 99
Thanks: 24
Thanked 0 Times in 0 Posts
Blatch is an unknown quantity at this point
Check if this is secure?

PHP Code:
$url htmlspecialchars($_GET["url"]);

$url_exist mysql_query("SELECT * FROM `websites` WHERE `url` = '$url' AND `status` = 1 ORDER BY `id`") or die(mysql_error());

if(!isset(
$url)) { 
    
header("Location: http://www.mysite.com/");
} else {
    if(
$_GET["url"] == $url && mysql_num_rows($url_exist) > 0) {
        
mysql_query("UPDATE `websites` SET `out` = `out` + 1 WHERE `url` = '$url'");        
        
header("Location: " $url);
    } else {
        
header("Location: http://www.mysite.com/");
    }

Is this safe or are there flaws? Please help.
Blatch is offline   Reply With Quote
Old 09-08-2009, 07:11 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Originally Posted by php.net/htmlspecialchars
The translations performed are:

* '&' (ampersand) becomes '&'
* '"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
* ''' (single quote) becomes ''' only when ENT_QUOTES is set.
* '<' (less than) becomes '&lt;'
* '>' (greater than) becomes '&gt;'
Better to use mysql_real_escape_string() (after removing the slashes added by magic_quote_gpc, if any)

PS:
PHP Code:
header("Location: " $url); 
Don't you need to validate the domain name?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
Blatch (09-08-2009)
Old 09-08-2009, 07:26 AM   PM User | #3
Blatch
New Coder

 
Join Date: Mar 2003
Location: USA
Posts: 99
Thanks: 24
Thanked 0 Times in 0 Posts
Blatch is an unknown quantity at this point
Ok changed it up.

You mean check if the domain is a real domain? I already did that in my submission form (checks to see if url of site is real and in existence) so I didn't think I would have to do it again. And if the site isn't in my database, it'll just redirect you to mysite instead of the url.

Anything else I should do?
Blatch is offline   Reply With Quote
Old 09-08-2009, 07:34 AM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
I already did that in my submission form (checks to see if url of site is real and in existence) so I didn't think I would have to do it again.
Before submission? That may not be enough. You'd need to validate all external data from server side, to save your tables from wrong data.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 09-08-2009, 07:42 AM   PM User | #5
Blatch
New Coder

 
Join Date: Mar 2003
Location: USA
Posts: 99
Thanks: 24
Thanked 0 Times in 0 Posts
Blatch is an unknown quantity at this point
But it will only update the table data if the website is in existence in the database, if not, it won't do anything. So it's pointless for the user to put in a random website in the url param. Right?
Blatch is offline   Reply With Quote
Old 09-08-2009, 08:03 AM   PM User | #6
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
So it's pointless for the user to put in a random website in the url param. Right?
Yes. That's OK. I thought there's an INSERT query
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 09-08-2009, 01:14 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Although it won't make a difference in this situation (because of you're if/else usage), header redirect should be followed by an exit(). This is because PHP will continue to process regardless of if a browser has been redirected (it has to wait until the end anyway when it receives its results).
Its a good habit to get into, and I'd recommend even changing what you have to reflect this. abduraooft covered the rest from the looks of it.
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
Blatch (09-08-2009)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:17 AM.


Advertisement
Log in to turn off these ads.