Help with PHP And Javascript
2013-12-31, 02:08 AM,
#1
I'm trying to place a Php variable in javascript code. From my understanding this isn't straight forward so i was wondering how i would go about doing that?

What i'm trying to do is get a php variable with a user's id in it into a CPALead Widget code, the part of the code i'm trying to get it into this url where it says "Variable Here". so i am unsure of what to do.

Code:
<script type="text/javascript" src="htt p://www.cpalead.com/cpalock.php?pub=**;&subid=VARIABLEHERE"></script>
Reply
2013-12-31, 02:32 AM,
#2
Assuming your PHP script has received (GET/POST) and verified a variable $var, you can use this code:

Code:
<script type="text/javascript" src="htt p://www.cpalead.com/cpalock.php?pub=**;&subid=<?php echo $var; ?>"></script>

The PHP script will interpret the code

Code:
<?php echo $var; ?>

and replace it with the value inside the JavaScript part. Please make sure to verify every value of this variable to make your script as secure as possible.

This place is intentionally left blank.
Reply
2013-12-31, 03:51 AM, (This post was last modified: 2013-12-31, 03:58 AM by lugubrious.)
#3
(2013-12-31, 02:32 AM)BlackHatSEO Wrote: Assuming your PHP script has received (GET/POST) and verified a variable $var, you can use this code:

Code:
<script type="text/javascript" src="htt p://www.cpalead.com/cpalock.php?pub=**;&subid=<?php echo $var; ?>"></script>

The PHP script will interpret the code

Code:
<?php echo $var; ?>

and replace it with the value inside the JavaScript part. Please make sure to verify every value of this variable to make your script as secure as possible.
Thanks!
I'll try this now, do you know of any way i can test to see that its putting the variable into the sub id and its displaying in the url properly?
edit:nvm i pasted the code you gave me outside the javascript and it showed the right id, thank you!
Reply
2013-12-31, 05:56 AM,
#4
Glad I could help you. You're welcome. ;-)

This place is intentionally left blank.
Reply
2014-01-01, 02:35 AM, (This post was last modified: 2014-01-01, 03:00 AM by lugubrious.)
#5
(2013-12-31, 05:56 AM)BlackHatSEO Wrote: Glad I could help you. You're welcome. ;-)

It seems the script doesn't work, after a survey is completed it always returns with "subid=501aaf9878d5d06c88b3d564a4167c0e"
edit:sorted it my self, confirmed it works
Reply
2014-01-03, 03:36 AM,
#6
And you can also make it shorter, if you have short tags enabled in php.ini:
PHP Code:
<?= $variable ?>

In your example:
PHP Code:
<script type="text/javascript" src="htt p://www.cpalead.com/cpalock.php?pub=**;&subid=<?= $variable ?>"></script> 
Latest Thanks - View all

reb0rn045(2014-01-03 03:43 AM) 
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Help Needed CPAgrip php script takumi 4 843 2017-01-24, 04:47 AM
Last Post: takumi
  SOME DATA IS NOT BEING INSERTED TO MYSQL DATABASE WITH PHP QwertySon 2 1,167 2016-11-21, 02:52 PM
Last Post: QwertySon
  php + mysql , I need help t0ks1ck 4 1,059 2016-09-19, 01:55 AM
Last Post: styx
  need a php line help t0ks1ck 8 1,056 2016-09-08, 09:01 PM
Last Post: styx
  [SHARE} High Quality Javascript ALERTS! Mimo 0 1,046 2016-07-11, 05:13 PM
Last Post: Mimo





About Us | Contact Us | CPA Elites | Advertise | Stats | Staff Team

© 2013-2017 CPA Elites Ltd
Enhanced by MyBB and WallBB
Return to top