473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Create/Update Php Session with Javascript

I am trying to create/update a Php Session with Javascript to confirm
if users have Javascript enabled.

My first thought was to create a Javascript that writes a script tag
referencing a php page, which sets a $_SESSION variable.

javascript.js:

<script type="text/javascript">
<!--//
document.write('<s'+'cript type="text/javascript"
src="javascript.php"></s'+'cript>');
//-->
</script>

javascript.php:

<?php
session_start();
$_SESSION['javascript'] = 'enabled';
?>

I can see that both the javascript.js and javascipt.php files are
executing from the web logs, but when I try to query the
$_SESSION['javascript'] variable from another page $_SESSION is empty.

Is it possible to create/update a Php Session with Javascript?

Might it be done using URLEncoded URL, Javascript XMLHttpRequest, or
something of the like?

Thank you for your assitance.

Respectfully,
Gary

Dec 15 '05 #1
10 3865
AN************************@yahoo.com writes:
I am trying to create/update a Php Session with Javascript to confirm
if users have Javascript enabled.


Uncle Google is your friend:

http://groups.google.com/group/comp....script+enabled

--
Bart

Dec 15 '05 #2
<html>
<head>
<title> Best way I know is... </title>
</head>
<body>
<?php
if(isset($_GET['js']))
{
echo "JS is on";
//
// Code for JS on
//
}
else
{
echo "
<form name='testjs'>
<input type='hidden' name='js' value='on'>
</form>
<script>
<!--
document.testjs.submit()
//-->
</script>
";
echo "JS is off";
//
// Code for js off
//
}
?>
</body>
</html>

Dec 15 '05 #3
Ian B wrote:
<html>
<head>
Not Valid. <URL:http://validator.w3.org/>
<title> Best way I know is... </title>
</head>
<body>
<?php
if(isset($_GET['js']))
{
echo "JS is on";
//
// Code for JS on
//
So if I happen to access the resource with "...?js=foo" you assume
client-side script support is enabled? What ridiculous kind of
"detection" is that? You should have at least used $_POST.
}
else
{
echo "
?>non-PHP content<?php

is faster and less error-prone.
<form name='testjs'>
<input type='hidden' name='js' value='on'>
</form>
<script>
Not Valid.
<!--
Unnecessary and potentially harmful.
document.testjs.submit()
Ohh yes, if that works (e.g. there is no submit button), users will be happy
when something is submitted without their interaction. Really. NOT.
//-->
Unnecessary and potentially harmful.
</script>
";
echo "JS is off";
No, it could as well be that such abuse of client-side scripting is blocked
by the UA.
[...]


There is no alt.php or comp.lang.php anymore (there is comp.lang.php.misc
for example) and Java != JavaScript. Furthermore, you should not crosspost
across top-level hierarchies (here: alt.* and comp.*).
X-Post reduced to clj.p and cl.js, F'up2 cl.js

PointedEars
Dec 15 '05 #4
Thomas 'PointedEars' Lahn wrote:

There is no alt.php or comp.lang.php anymore


Umm - since when?

http://groups.google.com/group/alt.php shows posts being made to
alt.php as of December 15 - isn't that today?

It also shows up on my news server...

Dec 15 '05 #5
Tony wrote:
Thomas 'PointedEars' Lahn wrote:
There is no alt.php or comp.lang.php anymore
Umm - since when?


Since now[1] ;-)
http://groups.google.com/group/alt.php shows posts being made to
alt.php as of December 15 - isn't that today?
Seriously:

Google Groups (formerly DejaNews) always was an archive that was independent
of Usenet. And they never removed any dead group (at least they did not
the last time I checked which was before the beta). Therefore, people
using Google Groups often post to dead groups and wonder why nobody or
only Google posters reply.

Since the beta, the independence from Usenet has increased as Google
is no longer simply mirroring Usenet, it allows users to create groups
that are not found on any news server.

On the other hand, alt.ALL is a very ... volatile hierarchy, as virtually
anyone can send newgroup and rmgroup.
It also shows up on my news server...


Which is?

It could be that my news server (news.arcor.de) simply does not have this
newsgroup. But since it appears to have much of the rest of alt.* (6201
groups here), I think it is more likely that your admin either ignored the
rmgroup or let the news server follow all control messages for this group
-- the difference between a good maintained news server and a bad one.

Hard to say which one applies, but I tend to the latter because of

a) the 23 latest postings

GMT domain of injecting news server
-------------------------------------------------
20:05 ntli.net
20:03 supernews.com
18:39 googlegroups.com
12:18 individual.net
10:50 telia.net
10:28 googlegroups.com
09:37 individual.net
08:59 googlegroups.com
03:14 googlegroups.com
02:37 googlegroups.com
01:58 comcast.com
00:07 ntli.net
2005-12-15 00:04 comcast.com
23:28 googlegroups.com
22:47 newsguy.com
21:53 googlegroups.com
21:46 euronet.nl
17:23 newsguy.com
07:44 btopenworld.com
2005-12-14 05:30 telus.net
23:46 googlegroups.com
22:43 individual.net
2005-12-13 22:42 news:43*********************@news.euronet.nl

(That was from Google's first page, sorted by date. I had to
dig that out _manually_ and there is XNAY, so please don't nail
me on that :))

This does not strike me as a widely distributed, active newsgroup (I
included the message ID of one posting so that you see where the action
really is):

- If you watch the times, there are large gaps up to 10 hours between
postings.
- If you watch the injecting servers and User-Agent headers, you see
almost only Web interfaces.
- If you watch the postings, what is posted there are mostly RTFM questions
often crossposted to other groups.
- And if you watch the threads, there is none of those postings with more
than two replies, highly unusual for a technical discussion group.

Compare comp.lang.php:

19:25 cistron.nl
19:12 cistron.nl
19:05 ntli.net
18:28 googlegroups.com
16:25 btopenworld.com
16:16 googlegroups.com
16:02 xs4all.nl
15:58 googlegroups.com
15:03 googlegroups.com
15:01 xs4all.nl
14:34 googlegroups.com
13:04 easynews.com
12:56 googlegroups.com
12:48 googlegroups.com
12:46 googlegroups.com
12:20 skynet.be
12:18 individual.net
12:01 googlegroups.com
11:58 googlegroups.com
11:14 googlegroups.com
11:06 googlegroups.com
10:53 googlegroups.com
2005-12-15 10:53 btopenworld.com

Google Groups is the majority, of course, but watch the times.
Threads have usually 4 and more postings.

Compare comp.lang.javascript:

19:59 prodigy.com
19:20 googlegroups.com
19:20 xs4all.nl
19:14 googlegroups.com
18:36 googlegroups.com
18:28 googlegroups.com (the precursor of this posting)
18:08 googlegroups.com
18:07 newsguy.com
17:43 comcast.com
17:35 arcor.de (me)
17:31 newsguy.com
17:19 arcor.de (me)
17:16 googlegroups.com
17:12 arcor.de (me)
17:04 googlegroups.com
16:57 googlegroups.com
16:55 arcor.de (!me)
16:50 demon.net
16:47 arcor.de (me)
16:47 xs4all.nl
16:22 googlegroups.com
16:19 arcor.de (me)
16:19 blueyonder.co.uk
16:11 googlegroups.com
16:01 googlegroups.com
15:30 newsguy.com
15:25 googlegroups.com
14:46 googlegroups.com
14:45 2005-12-15 iinet.net.au

(Because I am posting here, I added some more data than above.)

Threads have usually 4 and more postings. Despite Google Groups is the
majority, there are many different newsservers. And watch the times.

Now that strikes me as being a very active group :)
b) due to the ... volatility of ("chaos in" are the better words ;-)) alt.*,
several server admins just gave up and ignored a newgroup in this TLH for
which they just received a rmgroup before.

See also
<URL:http://groups.google.de/group/alt.config/browse_frm/thread/382424024c6cdc4d/563804dc0a2e62ed?lnk=st&q=rmgroup+alt.php&rnum=4&h l=de#563804dc0a2e62ed>

and other discussions. Therefore, I think it is best to use only the
appropriate hierarchy and newsgroup for PHP, comp.lang.php, and consider
alt.php and the like obsolete.

[1] So as for comp.lang.php, I stand corrected; I mixed that up with
de.comp.lang.php, which was splitted a while ago.
PointedEars
Dec 15 '05 #6
Try doing something like this in javascript.php to see if you have the
right session id:

echo "alert('$session_id');";

Dec 16 '05 #7
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

Dec 16 '05 #8
JRS: In article <22****************@PointedEars.de>, dated Thu, 15 Dec
2005 21:56:56 local, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <Po*********@web.de> posted :
Tony wrote:
Thomas 'PointedEars' Lahn wrote:
There is no alt.php or comp.lang.php anymore


Umm - since when?


Since now[1] ;-)


No. Both are recognised by the Demon news server, and Demon are
generally good at getting the newsgroups list right, both for additions
and removals.

In your urge to dominate this newsgroup you have formed the habit of
answering without sufficient care about getting things right. This
wastes more time than you might otherwise hope to save.

Stick to things where you have a reasonable chance of being right, and
check your facts and code before posting. And give up this dictator
complex - there's probably still wood to chop at Doorn.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Dec 16 '05 #9
Dr John Stockton wrote:
[...] Thomas 'PointedEars' Lahn <Po*********@web.de> posted :
Tony wrote:
Thomas 'PointedEars' Lahn wrote:
There is no alt.php or comp.lang.php anymore
Umm - since when?

Since now[1] ;-)


No. Both are recognised by the Demon news server [...]


Obviously you are unable to recognize humor or even subtile attempts at
that. I pity you.
PointedEars
Dec 17 '05 #10
<body>
<script language=javascript>
window.location.href="mypage.php?js=on";
<script>
<noscript>
<a href="mypage.php?js=off">click here to continue</a>
<noscript>
</body>
I am new to sessions, do somewhere in the code you wuold need to insert the
session stuff.

"Ian B" <ia********@gmail.com> wrote in message
news:11********************@g44g2000cwa.googlegrou ps.com...
<html>
<head>
<title> Best way I know is... </title>
</head>
<body>
<?php
if(isset($_GET['js']))
{
echo "JS is on";
//
// Code for JS on
//
}
else
{
echo "
<form name='testjs'>
<input type='hidden' name='js' value='on'>
</form>
<script>
<!--
document.testjs.submit()
//-->
</script>
";
echo "JS is off";
//
// Code for js off
//
}
?>
</body>
</html>

Jan 19 '06 #11

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

Similar topics

20
by: Janaka | last post by:
I tend to use the SqlDataAdapter class in WinForms projects because once the inital data is loaded any modifications can be easily added/updated through a call to the Update() method. I've found...
4
by: Christina N | last post by:
Can anyone give me a code example of how to use a global array to keep track of all active sessions (their sessionid, logontime, etc)? I need a code example, not a prosa description of what to...
5
by: ANTISPAM_garycnew_ANTISPAM | last post by:
I am trying to create/update a Php Session with Javascript to confirm if users have Javascript enabled. My first thought was to create a Javascript that writes a script tag referencing a php...
4
by: ccshine | last post by:
I have several textboxes, a gridview and an image in a panel that need to be updated based upon info entered into a textbox. Everything works like a champ when I don't use the Atlas UpdatePanel,...
2
by: Divya Khullar | last post by:
Is there a way of updating session variable in JS.
60
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?...
1
by: =?Utf-8?B?YWxiZXJ0bHk=?= | last post by:
How can I create a new session from the existing session in asp.net when new IE session is opened using javascript's window.open method or user's hyperlink click? I have a web application which...
1
by: MrZed | last post by:
I run into this problem, and I read many places that these is not solvable. I have one solution (workaround), not simple, a little trickier, limited, but possible and usable. My main problem...
2
by: WuBin | last post by:
Hi, I have a GridVew and a sqlDtaSurce control in ASP.NET real-time page. The sqlDtaSurce control use a complicated query to load data from a SQL database. This real-time page is reloaded by...
5
by: handoyo | last post by:
Hi all,i'm trying to show updated data in existing html td.. For example i got column that show last modified datetime,then i want to update data again,the column will changed to current time without...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.