GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   How do you call a PHP script from Javascript ? (https://gfy.com/showthread.php?t=431733)

qw12er 02-14-2005 01:13 PM

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

AdPatron 02-14-2005 01:16 PM

PHP is server-side and Javascript is client-side, which means the two will not be able to function together.

StuartD 02-14-2005 01:18 PM

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.

qw12er 02-14-2005 01:23 PM

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

StuartD 02-14-2005 01:29 PM

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.

Arowanna 02-14-2005 01:30 PM

try using an iframe

naitirps 02-14-2005 01:32 PM

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?

grumpy 02-14-2005 01:39 PM

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.

qw12er 02-14-2005 02:29 PM

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.

StuartD 02-14-2005 02:42 PM

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.

naitirps 02-14-2005 03:11 PM

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 :)

qw12er 02-14-2005 03:27 PM

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.

qw12er 02-14-2005 03:30 PM

[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...

naitirps 02-14-2005 03:37 PM

so dump to flatfile, and update hourly to your db then

or do it solely in xml...

AdPatron 02-14-2005 04:23 PM

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.

grumpy 02-14-2005 11:24 PM

cookies is he answer


All times are GMT -7. The time now is 02:40 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123