You are here: Re: Create/Update Php Session with Javascript « All PHP « IT news, forums, messages
Re: Create/Update Php Session with Javascript

Posted by ANTISPAM_garycnew_ANTISPAM on 12/16/05 03:50

Here's the solution:

/includes/meta.php

<?php session_start(); if (!$_SESSION['javascript']) { ?><script
type="text/javascript" src="/js/javascript.php"></script><?php } ?>


/js/javascript.php

<?php
session_start();

if (($_COOKIE['PHPSESSID']) || ($_GET['PHPSESSID'])) { ?>
<!--//
document.write('<s'+'cript type="text/javascript"
src="/includes/javascript.php?PHPSESSID=<?php if
($_COOKIE['PHPSESSID']) { echo $_COOKIE['PHPSESSID']; } else { echo
$_GET['PHPSESSID']; } ?>"></s'+'cript>');
//-->
<?php } ?>


/includes/javascript.php

<?php
session_id($_GET['PHPSESSID']);
session_start();

$_SESSION['javascript'] = 'enabled';
?>

The meta.php script is a global include file that initiates a request
to js/javascript.php if the $_SESSION['javascript'] variable is not
found.

The js/javascript.php script then executes a javascript initiated
request to the includes/javascript.php script using the PHPSESSID
variable and updates the user's php session $_GET['PHPSESSID'] with
$_SESSION['javascript'] = 'enabled';

It does have a short coming in that the first loaded page will not show
that $_SESSION['javascript'] is set. Only pages loaded after the
initial page will be usefull.

Hope this helps someone else.

Respectfully,


Gary

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация