Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

PHP Utils functions
I just wanted to share some useful PHP functions that I have written while
developing an application.

http://www.cybercomms.org/PHP/utils.inc

The .inc filename is just so it can be viewed, I use .php for include files
usually.

~~~~~~~~~~~~~~ utils.php ~~~~~~~~~~~~~~~~
<?php

function isValidPost()
{
if ( $_SERVER['REQUEST_METHOD'] == 'POST')
{
$referer = isset( $_SERVER['HTTP_REFERER']) ?
$_SERVER['HTTP_REFERER'] : "";
return (( parse_url( $referer, PHP_URL_HOST) ==
$_SERVER['HTTP_HOST']) &&
( parse_url( $referer, PHP_URL_PATH) ==
$_SERVER['PHP_SELF']));
}
else
return false;
}

function getReferer()
{
return $_SERVER["HTTP_REFERER"];
}

function getPost( $var)
{
return (isset( $_POST[ $var]) ? $_POST[ $var] : "");
}

//

function getParam( $param)
{
return (isset( $_GET[ $param]) ? $_GET[ $param] : "");
}

function getBaseDirectory()
{
return dirname( $_SERVER['SCRIPT_FILENAME']);
}

function getParamsFromURL( $url)
{
parse_str( parse_url( $url, PHP_URL_QUERY), $params);
return $params;
}

?>



Report this thread to moderator Post Follow-up to this message
Old Post
Aaron Gray
04-03-08 12:20 AM


Re: PHP Utils functions
"Aaron Gray" <ang.usenet@gmail.com> wrote in message
news:65hqojF2emkj8U1@mid.individual.net...
>I just wanted to share some useful PHP functions that I have written while
>developing an application.

> function getReferer()
> {
>    return $_SERVER["HTTP_REFERER"];
> }

Changed to :-

function getReferer()
{
return isset( $_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
}

Nothing like releasing something to find a bug or two :)

Aaron




Report this thread to moderator Post Follow-up to this message
Old Post
Aaron Gray
04-03-08 12:20 AM


Re: PHP Utils functions
..oO(Aaron Gray)

>I just wanted to share some useful PHP functions that I have written while
>developing an application.
>
>    http://www.cybercomms.org/PHP/utils.inc
>
>The .inc filename is just so it can be viewed, I use .php for include files
>usually.
>
>~~~~~~~~~~~~~~ utils.php ~~~~~~~~~~~~~~~~
><?php
>
>function isValidPost()
>{
>    if ( $_SERVER['REQUEST_METHOD'] == 'POST')
>    {
>        $referer = isset( $_SERVER['HTTP_REFERER']) ?
>$_SERVER['HTTP_REFERER'] : "";
>        return (( parse_url( $referer, PHP_URL_HOST) ==
>$_SERVER['HTTP_HOST']) &&
>                ( parse_url( $referer, PHP_URL_PATH) ==
>$_SERVER['PHP_SELF']));
>    }
>    else
>        return false;
>}

With this function I would never be able to post anything on your site.
The HTTP referrer is completely unreliable and should never be used for
things like above. Browsers don't have to send it and firewalls might
filter it out for security reasons.

Micha

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Fesser
04-03-08 12:20 AM


Re: PHP Utils functions
"Michael Fesser" <netizen@gmx.de> wrote in message
 news:1ce7v35lr9hma8lnqlu7p91ecbt226eu82@
4ax.com...
> .oO(Aaron Gray)
> 
>
> With this function I would never be able to post anything on your site.

Right, for the app I am working on I donot want first or third parties
posting to the app.

> The HTTP referrer is completely unreliable and should never be used for
> things like above. Browsers don't have to send it and firewalls might
> filter it out for security reasons.

Okay, thanks, is there another method I can use to make sure it was my app
posting ?

Thanks Micha, good feedback.

Aaron



Report this thread to moderator Post Follow-up to this message
Old Post
Aaron Gray
04-03-08 12:20 AM


Re: PHP Utils functions
Aaron Gray wrote:
> "Michael Fesser" <netizen@gmx.de> wrote in message
>  news:1ce7v35lr9hma8lnqlu7p91ecbt226eu82@
4ax.com... 
>
> Right, for the app I am working on I donot want first or third parties
> posting to the app.
> 
>
> Okay, thanks, is there another method I can use to make sure it was my app
> posting ?
>
> Thanks Micha, good feedback.
>
> Aaron
>
>
>

Aaron,

Micha is correct.  HTTP_REFERER is completely unreliable.  Not only will
it cause many of your existing users problems, it can be very easily
faked and won't stop someone from posting via a third party app.

You could put a random string in a hidden field and in the session.
When the form is posted, compare the two numbers.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================


Report this thread to moderator Post Follow-up to this message
Old Post
Jerry Stuckle
04-03-08 12:20 AM


Re: PHP Utils functions
"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:-KudnXs9eMLhfW7anZ2dnUVZ_vrinZ2d@comcast.com...
> Aaron Gray wrote: 
>
> Aaron,
>
> Micha is correct.  HTTP_REFERER is completely unreliable.  Not only will
> it cause many of your existing users problems, it can be very easily faked
> and won't stop someone from posting via a third party app.

Its HTTP teritory I see.

> You could put a random string in a hidden field and in the session. When
> the form is posted, compare the two numbers.

Okay, that would do the job nicely.

Many thanks,

Aaron



Report this thread to moderator Post Follow-up to this message
Old Post
Aaron Gray
04-03-08 12:20 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:16 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.