Connecting Tech Pros Worldwide Forums | Help | Site Map

technique to add and remove cookies after output

Jon Slaughter
Guest
 
Posts: n/a
#1: May 18 '07
I have developed a technique to add and remove cookies after output...
wondering if there is something else like this out there?

Jon



Mike P2
Guest
 
Posts: n/a
#2: May 18 '07

re: technique to add and remove cookies after output


On May 18, 3:29 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
Quote:
I have developed a technique to add and remove cookies after output...
wondering if there is something else like this out there?
>
Jon
Are you sending some JavaScript to do the work?

I think there shouldn't be a good reason to need to do this anyway,
unless you don't have interface code separated from business logic.

-Mike PII

Jon Slaughter
Guest
 
Posts: n/a
#3: May 19 '07

re: technique to add and remove cookies after output



"Mike P2" <sumguyovrthar@gmail.comwrote in message
news:1179518074.937833.39770@p77g2000hsh.googlegro ups.com...
Quote:
On May 18, 3:29 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
Quote:
>I have developed a technique to add and remove cookies after output...
>wondering if there is something else like this out there?
>>
>Jon
>
Are you sending some JavaScript to do the work?
>
I think there shouldn't be a good reason to need to do this anyway,
unless you don't have interface code separated from business logic.
>
-Mike PII
>
I'll explain it in another post later. It essentially lets you inline cookie
setters in the html code using php. It doesn't use javascript and
essentially is based on caching and callback's. It not be worth the trouble
as I'm stillt rying to iron out a few bugs but if I can clean it up some
then it might be worth it.

Jon


Jon Slaughter
Guest
 
Posts: n/a
#4: May 19 '07

re: technique to add and remove cookies after output


BTW, heres what I'm doing now,

Probably doesn't make much sense but if you look at the bottom of the page
you'll see how I add cookies into the form. After a user has clicked on a
button, the cookies there will be added. I just have to add the ability for
dynamic data of the cookies which I'll do tomorrow.

Essentially what this creates is a self contained paged. The line

if (isset($_SESSION['CALLBACKURL']) & !empty($_SESSION['CALLBACKURL']))

determines if its suppose to set the cookies or not and if so then does it
and then moves onto the next page. The code I have is working fine now but
probably is pretty buggy. Once I implement the dynamic code for the cookies
I'll post the code and see if anyone is interested in it and provide some
working examples. Right now the only page is the one below and it sets and
removes cookies. There are no other pages it links too.


you can goto to see it in action

http://www.jonslaughter.com/Index.php

The only pages on the site are Weblogin.php and Index.php. Weblogin only
holds the class.


<?php

session_start();
error_reporting(E_ALL); ini_set('display_errors','1');
ini_set('display_startup_errors','1'); ini_set('log_errors','1');
ini_set('display_startup_errors','1');

@require_once($_SERVER['DOCUMENT_ROOT'].'/Scripts/WebLogin.php');
$login = new WebLogin();


if (isset($_SESSION['CALLBACKURL']) & !empty($_SESSION['CALLBACKURL']))
{
$url = $_SESSION['CALLBACKURL'];
$login->SetCookies();


session_destroy();
unset($_SESSION);
unset($_COOKIE);


$url = '/Index.php';

echo '<meta content="0; URL='.$url.'" http-equiv="Refresh" />';
exit();
}

$login->DecodeCookies();






if (empty($_COOKIE) | !isset($_COOKIE))
{
echo "<br />No Cookies<br />\n";
}
else
{
echo "<br />Displaying Cookies<br />\n";
foreach($_COOKIE as $key =$val)
{
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$key. " =>
".htmlentities(serialize($val))."<br />\n";
}
}


$login->StopDB();
?>

<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Cookie Name: </label><input name="CookieName" value="Jo" type="text"
/><br />
<label>Cookie Data: </label><input name="CookieData" value="Blow"
type="text" /><br />
<input name="FormAction" type="submit" value="Add Cookie">
</form>
<?php $login->AddCookieP('Add Cookie', '/ShowCookies.php/', 'CookieName',
'CookieData', array('location' ='/')); ?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Cookie Name: </label><input name="CookieName" value="Jo" type="text"
/><br />
<input name="FormAction" type="submit" value="Delete Cookie">
</form>
<?php $login->DeleteCookieP('Delete Cookie', '/ShowCookies.php/',
'CookieName'); ?>

</body>
</html>



Jon Slaughter
Guest
 
Posts: n/a
#5: May 19 '07

re: technique to add and remove cookies after output



BTW, if you check your cookie files then you might notice something
different. I suppose redirecting to the same page isn't all that big of a
deal but also the cookies are encoded, encrypted, and hash validated which
is one reason for the login class(along with user login database stuff).


Closed Thread