By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,919 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,919 IT Pros & Developers. It's quick & easy.

technique to add and remove cookies after output

P: n/a
I have developed a technique to add and remove cookies after output...
wondering if there is something else like this out there?

Jon
May 18 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On May 18, 3:29 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
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

May 18 '07 #2

P: n/a

"Mike P2" <su***********@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
On May 18, 3:29 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
>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
May 19 '07 #3

P: n/a
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>

May 19 '07 #4

P: n/a

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).
May 19 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.