Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 18th, 2004, 12:59 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
JS to PHP Problem

I need to find another way to run a PHP script when a user leaves my website or closes their browser. The best way I've found to do this so far is with a popup using the ONUNLOAD event but I can't use a popup because of popup blockers. It must be ran when they leave and not before.

So how can I do this without a popup? Swap image somehow?

Here's basically how I'm doing it now:

<script>
var ScriptURL = "stats.php";

function postinfo() {
var poststats = ScriptURL + "?" + stats + "=" + statsvar; window.open(poststats); //call URL
}
</script>

<body onunload="postinfo()">

etc...

I've spent the last 4 days searching the net and forums for another way with no luck. Some hint about an image swap and I think that would be perfect but I'm not good with JavaScript. I would of used PHP to do it all but PHP can't do some of the stuff I need and JS can.

Thanks...

Abbadon

Reply With Quote
  #2  
Old October 20th, 2004, 02:37 AM
niko_zeta niko_zeta is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Rossmoyne, WA, Australia
Posts: 105 niko_zeta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to niko_zeta Send a message via AIM to niko_zeta Send a message via Yahoo to niko_zeta
RE: JS to PHP Problem

Sorry not to offer you a solution here, but it seems to me that what you are trying to do violates one of the internet's most basic assumptions: that a user is free to terminate interaction with a website when he/she desires, and the only way a user usually has to do this is to close the window.

This is where you could offer the user another way to finish interacting with your website: give them a "log out securely" button, that opens up the php script, which runs and closes itself automatically. Because the user, in this case, chooses to press the button, a pop-up blocker will not be activated.

However, if the user decides to close the window, there is nothing you can (or should!) do. It would be the same principle if the user's computer suddenly crashed, or if the user unplugged the computer to stop a download or a credit card purchase. You must make that allowance and do all you can to direct the user to the "log out" button instead of the little cross :-)

Reply With Quote
  #3  
Old October 20th, 2004, 11:01 AM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: JS to PHP Problem

What niko_zeta said is correct, but there is another way to get a PHP script to run than a popup window: use an image.

In your javascript, create a new Image object, then assign the source the script you want to run:
Code:
<script>
var ScriptURL = "stats.php";

function postinfo() {
   var img = new Image();
   img.src = ScriptURL + "?" + stats + "=" + statsvar;
}
</script>

<body onunload="postinfo()">


This isn't fool-prrof, but you will probably have more luck than with pop-ups.

Reply With Quote
  #4  
Old October 21st, 2004, 06:40 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: JS to PHP Problem

if you threw an infinite loop in the page checking to see if connection_aborted(), then used ignore_user_abort() that might work.

but i've not played with it lately.

Reply With Quote
  #5  
Old October 22nd, 2004, 02:22 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: JS to PHP Problem

Thanks Honcho... That works pretty good. I'ld say about 80-90 percent of the time.

Notepad... I'll look into that as a way to possibly make it a little more reliable... Thanks

Abbadon

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > JS to PHP Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Try It Free




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway