CPAElites is for sale! As a result of the 2 months CEO absence: Please click [here] to read more!


Help with PHP And Javascript
2013-12-30, 10:38 PM,
#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-30, 11:02 PM,
#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, 12:21 AM, (This post was last modified: 2013-12-31, 12:28 AM by lugubrious.)
#3
(2013-12-30, 11:02 PM)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, 02:26 AM,
#4
Glad I could help you. You're welcome. ;-)

This place is intentionally left blank.
Reply
2013-12-31, 11:05 PM, (This post was last modified: 2013-12-31, 11:30 PM by lugubrious.)
#5
(2013-12-31, 02:26 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, 12:06 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
Reply


Related Threads
Thread Author Replies Views Last Post
  OGAds offer API output help please AbdouMotDz 3 2,962 2020-04-24, 01:52 AM
Last Post: WORLD_PEACE
  OfferToro Postback Help Socialhits 5 2,484 2020-04-06, 04:55 PM
Last Post: thysdw
  [Help] Angular Niki 0 354 2019-05-18, 10:46 PM
Last Post: Niki
  Need Few Instructions That Can Help me Create Video Whiteboard Animation EvaHarrison 1 743 2018-08-17, 02:23 PM
Last Post: CharlieHarper
  ANNOUNCEMENT How To Protect And Secure Your WordPress Websites For Free [ --- The previous Admin --- Guide] CPAElites Team 23 10,524 2018-03-11, 04:58 PM
Last Post: krypton_bleu





About Us | Contact Us | CPAElites | Advertise | Stats

Copyright © 2013 - 2020 by (company to be announced later)
Temporarily (!) powered by MyBB, fixed (repaired) and enhanced by Charlie Harper (GitHub) aka Charles Francis Harper (Wikipedia)
Return to top
This forum uses Lukasz Tkacz MyBB addons.