Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 02-14-2005, 01:13 PM   #1
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
How do you call a PHP script from Javascript ?

I need to call a PHP Script from a Javascript segment of code. I also need the Javascript to stop it's execution while the PHP script does it job. Once the PHP script is done the Javascript must continue where it was.

Is such a thing possible. If it's ... how.
(I know it's possible with sockets, but seems too much trouble that way...)

Thanks
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 01:16 PM   #2
AdPatron
No commissions, no fees.
 
Industry Role:
Join Date: Apr 2003
Location: USA
Posts: 17,706
PHP is server-side and Javascript is client-side, which means the two will not be able to function together.
AdPatron is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 01:18 PM   #3
StuartD
Sofa King Band
 
StuartD's Avatar
 
Join Date: Jul 2002
Location: Outside the box
Posts: 29,903
Quote:
Originally Posted by CollegeSucks
PHP is server-side and Javascript is client-side, which means the two will not be able to function together.
that's exactly right.
StuartD is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 01:23 PM   #4
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
No it's possible ... in fact it's even easy to do it ...

in Javascript :
window.navigate("http://yourPHPScript.php");
and that will do ...

but in my case I'm doing it in the onBeforeUnload event. Since I call a other page while the browser is closing the PHP script never receive the info and create an empty record in my DB.

So i would need something that loops so the onbeforeUnload don't finish until the php script is done. Basically I need a fucntion that block Javascript execution until the new page isn't completly loaded
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 01:29 PM   #5
StuartD
Sofa King Band
 
StuartD's Avatar
 
Join Date: Jul 2002
Location: Outside the box
Posts: 29,903
Well, if you're going to a separate page entirely... what you could do is split your function into two new functions, so the first half gets done... then it calls the php script, and then the php script runs a "onLoad" so that it refers back to the original document and the second half of your javascript.
StuartD is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 01:30 PM   #6
Arowanna
Confirmed User
 
Join Date: Dec 2004
Location: Belgium
Posts: 248
try using an iframe
Arowanna is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 01:32 PM   #7
naitirps
Confirmed User
 
Join Date: May 2004
Location: ...
Posts: 761
lots of ways you can get shit like that to work... usually better to stuff in php first then pass to javascript works fine for me all the time... what exactly are you trying to do?
__________________
Programmer
ICQ 44035273 | AIM spritwork | Email spritian at spritian dot com
naitirps is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 01:39 PM   #8
grumpy
Too lazy to set a custom title
 
grumpy's Avatar
 
Join Date: Jan 2002
Location: Holland
Posts: 9,870
you can call an update script from a page in java anytime you want with a little trick

put an image on a page like this < img src=whatever height=1 width =1 name="trick" >

in a java script you can do the following
trick.src = whatever.php

hope this helps.
__________________
Don't let greediness blur your vision | You gotta let some shit slide
icq - 441-456-888
grumpy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 02:29 PM   #9
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
Quote:
Originally Posted by naitirps
lots of ways you can get shit like that to work... usually better to stuff in php first then pass to javascript works fine for me all the time... what exactly are you trying to do?
basically I'm trying to monitor everything my surfers do on my web site. (Where they clic, which cat. they prefer etc ... ) Since I don't want to generate a lot of traffic to my database I want to use the surfers computer as much as possible. So the idea is to do as much gathering as possible in Javascript and when the surfer close it's browser (or quit my page) send the information to a php script on my server which will insert the info into my database.
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 02:42 PM   #10
StuartD
Sofa King Band
 
StuartD's Avatar
 
Join Date: Jul 2002
Location: Outside the box
Posts: 29,903
Quote:
Originally Posted by qw12er
basically I'm trying to monitor everything my surfers do on my web site. (Where they clic, which cat. they prefer etc ... ) Since I don't want to generate a lot of traffic to my database I want to use the surfers computer as much as possible. So the idea is to do as much gathering as possible in Javascript and when the surfer close it's browser (or quit my page) send the information to a php script on my server which will insert the info into my database.
I'm not sure I get it quite right, but it seems to me that your server and database will do the same amount of work either which way, just at a different time in the page load. And if this is the case, then perhaps caching stats? Writing to a file? sessions and then session dumping after?
I dunno... just seems like having javascript do stuff when they close their browser will result in a LOT of lost data and won't save much if anything on serve load.
StuartD is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 03:11 PM   #11
naitirps
Confirmed User
 
Join Date: May 2004
Location: ...
Posts: 761
easy way to do it is at the top of every script include a small php inc file that just monitors the ref, dt, ip etc inserting to your db... you can also append what they clicked on in the uri so you can track it that way as well... no need for javascript.

obviously if there is no more activity, they've closed the browser, because up until that point you've monitored where they are going in the site
__________________
Programmer
ICQ 44035273 | AIM spritwork | Email spritian at spritian dot com
naitirps is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 03:27 PM   #12
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
Quote:
Originally Posted by NichePay - StuartD
I'm not sure I get it quite right, but it seems to me that your server and database will do the same amount of work either which way, just at a different time in the page load. And if this is the case, then perhaps caching stats? Writing to a file? sessions and then session dumping after?
I dunno... just seems like having javascript do stuff when they close their browser will result in a LOT of lost data and won't save much if anything on serve load.
You're probably right for the amount of data loses but I want to test it ... Cause no it won't do the same amount of work for the server ... If I can use Javascript the way I want I will be able to connect to my database and update it only once instead of "X" numbers of time (depending of what my surfers do on my site).

Might represent a good saving (Processing power) if my site gets lot of traffic.
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 03:30 PM   #13
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
[QUOTE=naitirps]easy way to do it is at the top of every script include a small php inc file that just monitors the ref, dt, ip etc inserting to your db... you can also append what they clicked on in the uri so you can track it that way as well... no need for javascript.
QUOTE]

I know I could do this like you wrote, but it will result in way to much connection to my database...
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 03:37 PM   #14
naitirps
Confirmed User
 
Join Date: May 2004
Location: ...
Posts: 761
so dump to flatfile, and update hourly to your db then

or do it solely in xml...
__________________
Programmer
ICQ 44035273 | AIM spritwork | Email spritian at spritian dot com
naitirps is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 04:23 PM   #15
AdPatron
No commissions, no fees.
 
Industry Role:
Join Date: Apr 2003
Location: USA
Posts: 17,706
Quote:
Originally Posted by qw12er
So i would need something that loops so the onbeforeUnload don't finish until the php script is done. Basically I need a fucntion that block Javascript execution until the new page isn't completly loaded

Good luck with that -lol.
AdPatron is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-14-2005, 11:24 PM   #16
grumpy
Too lazy to set a custom title
 
grumpy's Avatar
 
Join Date: Jan 2002
Location: Holland
Posts: 9,870
cookies is he answer
__________________
Don't let greediness blur your vision | You gotta let some shit slide
icq - 441-456-888
grumpy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.