javascript variable inside php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
newbiz
Forum Newbie
Posts: 1
Joined: Fri Mar 26, 2010 8:10 am

javascript variable inside php

Post by newbiz »

hi,

i have searched high and low and cannot find what i want. I understand the javascript is client side and php is server side. What i am trying to do is pass the javascript variable var url to the domainCheck($url) php function:

Code: Select all

 
<script language="javascript" type="text/javascript">
 
function passURL()
{
var url = document.getElementById('url').value;
alert ("<?php domainCheck("*[b]*want to get var url in here**[/b]") ?>");
}
</script>
 
once i have the javascript value inside the php variable, i can pass it to the following domainCheck($url) php function:

Code: Select all

/***** start check domain availability *****/
<?php
function domainCheck($url)
{
$domain = $url;
$ch = curl_init();
$postData = "SessionID=" . $sessionID;
$postData .= "&" . "Type=Domains";
$postData .= "&" . "Object=Domain";
$postData .= "&" . "Action=Availability";
$postData .= "&" . "Domain=" . $domain;
curl_setopt($ch, CURLOPT_URL, "https://www.distributeit.com.au/api/query.pl");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
/**
* $result will contain:
* (Domain): OK: Minimum=(years)&Maximum=(years)
* OR
* (Domain): ERR: (Error Code),(Error Description)
**/
$result = curl_exec($ch);
/* you may want to check curl_error($ch); */
curl_close($ch);
/***** end check domain avaiability *****/
echo $result;
}
?>
 
Is this possible? If not, or if there is a better way to do what i am trying to achieve i would be very grateful to hear.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: javascript variable inside php

Post by requinix »

newbiz wrote:I understand the javascript is client side and php is server side.
If so, you'd know what you're trying to do with that code is impossible.

Either submit the form normally or use AJAX.
Post Reply