473,802 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_REFER ER"];
}

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

//

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

function getBaseDirector y()
{
return dirname( $_SERVER['SCRIPT_FILENAM E']);
}

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

?>
Apr 2 '08 #1
7 2016

"Aaron Gray" <an********@gma il.comwrote in message
news:65******** *****@mid.indiv idual.net...
>I just wanted to share some useful PHP functions that I have written while
developing an application.
function getReferer()
{
return $_SERVER["HTTP_REFER ER"];
}
Changed to :-

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

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

Aaron

Apr 2 '08 #2
..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
Apr 2 '08 #3
"Michael Fesser" <ne*****@gmx.de wrote in message
news:1c******** *************** *********@4ax.c om...
.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.
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
Apr 2 '08 #4
Aaron Gray wrote:
"Michael Fesser" <ne*****@gmx.de wrote in message
news:1c******** *************** *********@4ax.c om...
>.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.

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
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.
js*******@attgl obal.net
=============== ===

Apr 2 '08 #5
"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:-K************** *************** *@comcast.com.. .
Aaron Gray wrote:
>"Michael Fesser" <ne*****@gmx.de wrote in message
news:1c******* *************** **********@4ax. com...
>>.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.

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

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
Apr 2 '08 #6
Greetings, Aaron Gray.
In reply to Your message dated Wednesday, April 2, 2008, 20:37:02,

function getReferer()
{
return isset( $_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
}
Nothing like releasing something to find a bug or two :)
Renaming functions is bad, you know?
Syntactic sugar is a VERY bad practice.
It never add anything to the code functionality and only confuse anyone who
will be supporting this code after you.
--
Sincerely Yours, AnrDaemon <an*******@free mail.ru>

Jun 27 '08 #7
AnrDaemon wrote:
Greetings, Aaron Gray.
In reply to Your message dated Wednesday, April 2, 2008, 20:37:02,

>function getReferer()
{
return isset( $_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
}
>Nothing like releasing something to find a bug or two :)

Renaming functions is bad, you know?
If you mean: you should have refactored it, you are right
Syntactic sugar is a VERY bad practice.
On the contrary. Legibility is everything. If a function has the wrong
name, make it have the right one. Most loops are just "syntactic sugar"
from other loops.
It never add anything to the code functionality and only confuse anyone who
will be supporting this code after you.
It adds legibility to the code, thereby _reducing_ confusion for anyone
who will be supporting the code after you.
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
997
by: arm developer | last post by:
in using ADS 1.2, does utils.h = Utils.h for example ... in windows XP TIA.
1
1489
by: venkatesh | last post by:
Hi, I am trying to use id-utils to browse a C++ source code (with .cpp extensions for the filenames). The problem I face is that mkid (which creates the ID database) doesn't parse the .cpp files at all. The command that I give is:
2
3793
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short- cut solution for finding collisions in SHA-1 . Their result
2
3759
by: Samuel | last post by:
Hello, I am trying to convert a local time into UTC ISO8601, then parse it back into local time. I tried the following: ---------------------- #!/usr/bin/python import time import datetime import xml.utils.iso8601
7
5908
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll route. The problem being that I can't call these functions from the query designer in Access. I decided that I would try the route of declaring the functions from the dll file the same way you would for the Windows API. Access then complains that...
0
1020
by: Mark Sapiro | last post by:
email.Utils.parseaddr('Real Name ((comment)) <address@example.com>') returns ('comment <address@example.com>', 'Real') Granted the string above is invalid as RFC 2822 does not allow parentheses within comments, but most mail agents seem to at least take the contents of the angle brackets as the address.
2
1488
by: zeal elite | last post by:
Hi, I am looking for substring search python program without using the built in funtions like find, or 'in'. Appreciate it. Thanks in advance. zeal _________________________________________________________________ Find a local pizza place, music store, museum and more…then map the best
6
1707
by: Jesse Aldridge | last post by:
In an effort to experiment with open source, I put a couple of my utility files up <a href="http://github.com/jessald/python_data_utils/ tree/master">here</a>. What do you think?
1
1703
by: Roopesh | last post by:
Hi, I tried using parseaddr of email.utils, but it gave the following result when the name had a comma inside. ('', 'K') Thanks and Regards, Roopesh
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.