RE: Session ID
by "jeremy" <jeremy(at)localnetamerica.com>
|
| Date: |
Mon, 16 Sep 2002 12:53:25 -0400 |
| To: |
"'Keith Sellars'" <Keith(at)webgraffix.com>, <hwg-languages(at)hwg.org> |
| In-Reply-To: |
S0026260871 |
| |
todo: View
Thread,
Original
|
|
Here is a script that I use. Even though I soley rely on cookies, and
not sessions, the code here used to check for cookie support is the same
regardless.
-- If this comes across all messed up, let me know and I will send it
differently
<? include("/usr/local/etc/httpd/dbconnect/parrot.php");
function generateID()
{
global $mysql_link;
global $uniqueSessionID;
$uniqueSessionID = md5(uniqid(rand()));
$query = "SELECT SessionID FROM cart WHERE
SessionID='$uniqueSessionID' ";
$mysql_result = mysql_query($query, $mysql_link);
if(mysql_num_rows($mysql_result) != 0) {
$match = 1;
}
if($match=="1") {
generateID();
}
}
function addtocart($ProductID,$quantity,$dropdown,$dropdown2)
{
global $mysql_link;
global $corrupt;
$ProductID=$ProductID+0;
if(!is_numeric($ProductID)) {
$corrupt=1;
}
$quantity=$quantity+0;
if(!is_numeric($quantity)) {
$corrupt=1;
}
if(!isset($corrupt)) {
$corrupt=0;
$ProductID = addslashes($ProductID);
$quantity = addslashes($quantity);
if($dropdown!="") {
$dropdown = addslashes($dropdown);
}
if($dropdown2!="") {
$dropdown2 = addslashes($dropdown2);
}
$query = "INSERT INTO cart VALUES('',
'".$_COOKIE['SessionID']."', '$ProductID', '$dropdown', '$dropdown2',
'$quantity', NOW()) ";
$mysql_result = mysql_query($query, $mysql_link);
}
}
include("variablelist.php");
if(!eregi("$siteurl", $_SERVER['HTTP_REFERER'])) {
header("Location: http://$siteurl");
}else{
if(!isset($_GET['verify'])) { // MEANING THAT COOKIES ARE NOT
BEING VERIFIED
if(!isset($_COOKIE['SessionID'])) { // COOKIE DOES NOT
EXIST - NEW CUSTOMER OR JUST TURNED ON COOKIES
generateID();
setcookie("SessionID", "$uniqueSessionID",
time()+18000, "/", "", "0");
// SEND BACK TO THIS PAGE, BUT TRIGGER THE
COOKIE VERIFICATION PAGE/CODE BELOW
if(!isset($_POST['fromverification'])) {
// MAKE CERTAIN TO HAVE HIDDEN FIELD CALLED fromverification IN ALL
FORMS **POSTING** TO THIS PAGE FOR ADD-TO-CART FUNCTIONALITY
$ProductID=$_GET['ProductID'];
$quantity=$_GET['quantity'];
$dropdown=$_GET['dropdown'];
$dropdown2=$_GET['dropdown2'];
header("Location:
addtocart.php?ProductID=$ProductID&quantity=$quantity&dropdown=$dropdown
&dropdown2=$dropdown2&verify=1");
}else{
$ProductID=$_POST['ProductID'];
$quantity=$_POST['quantity'];
$dropdown=$_POST['dropdown'];
$dropdown2=$_POST['dropdown2'];
header("Location:
addtocart.php?ProductID=$ProductID&quantity=$quantity&dropdown=$dropdown
&dropdown2=$dropdown2&verify=1");
}
}else{ // COOKIE DOES EXIST - WILL ATTEMPT TO ADD
PRODUCT TO SHOPPING CART
if(isset($_POST['ProductID'])) {
addtocart($_POST['ProductID'],
$_POST['quantity'], $_POST['dropdown'], $_POST['dropdown2']);
}else{
addtocart($_GET['ProductID'],
$_GET['quantity'], $_GET['dropdown'], $_GET['dropdown2']);
}
if($corrupt==1) {
header("Location: submissionerror.php");
}else{
header("Location: viewcart.php");
}
}
}else{ // COOKIES ARE BEING VERIFIED
if(isset($_COOKIE['SessionID'])) { // GETS EXECUTED IF
COOKIES WERE SUCCESFULLY SET ABOVE
addtocart($_GET['ProductID'], $_GET['quantity'],
$_GET['dropdown'], $_GET['dropdown2']);
if($corrupt==1) {
header("Location: submissionerror.php");
}else{
header("Location: viewcart.php");
}
}else{ // THIS PAGE IS DISPLAYED WHEN COOKIES CANNOT BE
VERIFIED
$title="Cookies Not Enabled";
include("header.php");
?>
<form method="post" action="addtocart.php" />
<input type="hidden" name="ProductID" value="<?
if(isset($_GET['ProductID'])) { echo $_GET['ProductID']; }else{ echo
$_POST['ProductID']; } ?>" />
<input type="hidden" name="quantity" value="<?
if(isset($_GET['quantity'])) { echo $_GET['quantity']; }else{ echo
$_POST['quantity']; } ?>" />
<input type="hidden" name="dropdown" value="<?
if(isset($_GET['dropdown'])) { echo $_GET['dropdown']; }else{ echo
$_POST['dropdown']; } ?>" />
<input type="hidden" name="dropdown2" value="<?
if(isset($_GET['dropdown2'])) { echo $_GET['dropdown2']; }else{ echo
$_POST['dropdown2']; } ?>" />
<input type="hidden" name="fromverification"
value="1" />
<br />
<table width="675" border="0" cellspacing="0"
cellpadding="0" align="center">
<tr>
<td><br /><span class="s8">
Your Domain.com uses cookies to enhance your
shopping experience.<br />
In order to purchase a product, you must have
cookies enabled. To enable them, follow the instructions below.<br /><br
/>
<b>Netscape 6</b><br />
<ol>
<li>Select the 'Edit' Menu</li>
<li>Select 'Preferences'</li>
<li>Select the 'Advanced' Category</li>
<li>Select 'Cookies'</li>
<li>Enable cookies on the bottom right</li>
</ol>
<b>Netscape Navigator/Communicator</b><br />
<ol>
<li>Select the 'Edit' Menu</li>
<li>Select 'Preferences'</li>
<li>Select the 'Advanced' Category</li>
<li>Enable cookies on the bottom right</li>
</ol>
<b>Microsoft Internet Explorer 6.0</b><br />
<ol>
<li>Select the 'Tools' Menu</li>
<li>Select 'Internet Options'</li>
<li>Select the 'Privacy' Tab</li>
<li>Select the 'Advanced' button near the
middle</li>
<li>Make certain that 'Accept First-Party
cookies' is selected (you may have to first select the 'Override
automatic cookie handling option')
</ol>
<b>Microsoft Internet Explorer 5.0/5.5</b><br />
<ol>
<li>Select the 'Tools' Menu</li>
<li>Select 'Internet Options'</li>
<li>Select the 'Security' Tab</li>
<li>Select the 'Custom Level...' button at the
bottom</li>
<li>About one-third of the way down there is a
section titled 'Cookies'</li>
<li>Enable cookies</li>
</ol>
<b>Microsoft Internet Explorer 4.0</b><br />
<ol>
<li>Select the 'View' Menu</li>
<li>Select 'Internet Options'</li>
<li>Select the 'Advanced' Tab</li>
<li>About two-thirds of the way down the window
there is a yellow triangle with an exclamation mark inside of it</li>
<li>Enable cookies</li>
</ol>
<b>AOL</b><br />
<ol>
<li>Select the 'My AOL' Menu</li>
<li>Select 'Preferences'</li>
<li>Select the 'WWW' icon</li>
<li>Select the 'Security' Tab</li>
<li>Select the 'Custom Level...' button at the
bottom</li>
<li>About one-third of the way down there is a
section titled 'Cookies'</li>
<li>Enable cookies</li>
</ol>
</span></td>
</tr>
<tr><td><br /></td></tr>
<tr>
<td><input type="image"
src="images/b-enablecookies.jpg" border="0" /> <input type="submit"
value="try again" /></td>
</tr>
</table>
</form>
<? include("footer.php");
}
}
}
?>
Jeremy Brown
Director of Web Technology
Hafenbrack Marketing and Communications
http://www.hafenbrack.com
(937) 859-0730
-----Original Message-----
From: owner-hwg-languages(at)hwg.org [mailto:owner-hwg-languages(at)hwg.org]
On Behalf Of Keith Sellars
Sent: Monday, September 16, 2002 12:34 PM
To: hwg-languages(at)hwg.org
Subject: Re: Session ID
Hank,
Is there a way for ME to test, with the php script itself, whether or
not
they can accept cookies and echo a "yes" or "no" back to the screen to
inform me of such?
Thanks,
Keith D Sellars
WebGraffix
www.webgraffix.com
"Making database sites seem easy"
----- Original Message -----
From: "Hank Marquardt" <hmarq(at)yerpso.net>
To: "Keith Sellars" <Keith(at)webgraffix.com>
Cc: <hwg-languages(at)hwg.org>
Sent: Monday, September 16, 2002 11:44 AM
Subject: Re: Session ID
> Looks more like they are blocking cookies either specifically for this
> site, or globally -- That means you'll probably either need to put the
> 'cookies required' language on the home page, or handle propogation
and
> testing for the session id yourself -- trans-sid will do the work of
> sending the session id, but you'll need to do the testing for
> $_GET/$_POST['PHPSESSID'] yourself and then use the session_id() to
set
> it yourself to prevent assignment of a new session on each page.
>
> I've seen this problem materialize on a lot of sites lately with the
> shift register_globals = off -- the reason is that trans-sid by itself
> used to be sufficient because $PHPSESSID would be registered in the
> global namespace regardless with register_globals=on -- so the
> session_start() call would find it even if it came in with GET/POST,
now
> with the default off, you have to explicitly do a little
> testing/assignment from the $_GET/$_POST arrays for it to work ...
>
> But at the root, it occurs because the client is likely rejecting the
> initial cookie --
>
>
> On Mon, Sep 16, 2002 at 11:20:00AM -0400, Keith Sellars wrote:
> > Hi guys,
> >
> > I have a question for you. It seems as if one of the schools that
are
using
> > www.SchoolPad.net (a site we designed last year and are updating
now) is
> > experiencing a situation that, for some reason, is NOT assigning
them a
> > PHPSESSIONID. Since the webadmin/index.php script checks for the
existence
> > of a PHPSESSIONID and gives them an "error" page otherwise, this is
a
> > problem. Since this is a security check, I really would like to
keep
this
> > feature in place (Or as an option replace it with something equally
> > effective, although I really don't want to go that route because I
want
it
> > to be server side, not client side).
> >
> > I am verifying this, but it seems as if this is the only school that
is
> > experiencing this, and it does not matter which computer on their
network is
> > being used, which leads me to believe that it is an issue with
network
> > security settings. Is there anything that anyone is aware of that
could
be
> > causing this?
> >
> > Thanks,
> > Keith D Sellars
> > WebGraffix
> > www.webgraffix.com
> >
> > "Making database sites seem easy"
> >
>
> --
> Hank Marquardt <hank(at)yerpso.net>
> http://web.yerpso.net
> GPG Id: 2BB5E60C
> Fingerprint: D807 61BC FD18 370A AC1D 3EDF 2BF9 8A2D 2BB5 E60C
> *** Web Development: PHP, MySQL/PgSQL - Network Admin: Debian/FreeBSD
> *** PHP Instructor - Intnl. Webmasters Assn./HTML Writers Guild
> *** Beginning PHP && PHP II -- Starting March 25, 2002
> *** See /services/classes
>
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA
This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.