Solved

how to excute a script to show on a webpage

Posted on 2011-03-08
43
224 Views
Last Modified: 2012-08-13
i have a script that which when run from a browser url it returns the requested info
rwebsite.aspx?dialplan=004477909999

how can i create a webpage that a user enter the above dialplan in an input field and submits the request. the results return and the viewed

0
Comment
Question by:daz1234
  • 22
  • 21
43 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35069026
You would use an HTML form to receive the data string that goes into the URL.  Then you would use CURL or file_get_contents to send the completed URL to the rwebsite.aspx script.  Can you give us the actual URL you want to use?  I can give you a code example.
0
 

Author Comment

by:daz1234
ID: 35069045
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35069108
Thanks, this shows how that might be used to call the ecocaller web service.
<?php // RAY_temp_daz1234.php
error_reporting(E_ALL);


// FROM THE ORIGINAL POST AT EE
// rwebsite.aspx?dialplan=004477909999


// THE FULLY QUALIFIED URL OF THE WEB SERVICE WE WANT TO TALK TO
$url = 'https://www.ecocaller.com/secure/ratewebsite.aspx?dialplan=';

// DEFAULT VALUES ARE EMPTY
$dat = NULL;

// IF THERE IS DATA CALL THE WEB SERVICE
if (!empty($_GET["d"]))
{
    $dat = $_GET["d"];
    $url = $url . $dat;
    $htm = file_get_contents($url);

    // SHOW WHAT CAME BACK
    echo htmlentities($htm);
}


// END OF PHP PROCESSING - DROP INTO HTML TO PUT UP THE FORM
?>
ENTER THE PHONE NUMBER LIKE "004477909999"
<form>
<input name="d" value="<?php echo $dat; ?>" />
<input type="submit" />
</form>

Open in new window

0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35069114
See line 23.  You may want to "tidy up" the returned data string.  You might also want to contact ecocaller and find out if they have an API.

HTH, ~Ray
0
 

Author Comment

by:daz1234
ID: 35069211
Hi Ray,

Line 23 echo htmlentities($htm); is not returning anything. Any thoughts?
0
 

Author Comment

by:daz1234
ID: 35069225
The returned string shoud show like below:

Ireland-Mobile-Vodafone Rate 0.0745 £/min
Ireland-Mobile-Vodafone Rate 0.0871 €/min
Ireland-Mobile-Vodafone Rate 0.1199 $/min
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35069238
Try that script on my server.  It may be that your host has disabled your ability to get to foreign web services.  If that is the case, get a new host.
http://www.laprbass.com/RAY_temp_daz1234.php?d=004477909999
0
 

Author Comment

by:daz1234
ID: 35069242
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35069308
Let's try the code this way.  Where is ecocaller.com hosted?
<?php // RAY_temp_daz1234.php
error_reporting(E_ALL);


// FROM THE ORIGINAL POST AT EE
// rwebsite.aspx?dialplan=004477909999


// THE FULLY QUALIFIED URL OF THE WEB SERVICE WE WANT TO TALK TO
$url = 'https://www.ecocaller.com/secure/ratewebsite.aspx?dialplan=';

// DEFAULT VALUES ARE EMPTY
$dat = NULL;

// IF THERE IS DATA CALL THE WEB SERVICE
if (!empty($_GET["d"]))
{
    $dat = $_GET["d"];
    $url = $url . $dat;
    $htm = file_get_contents($url);

    if (!$htm) echo "<br/>WEB SERVICE AT $url FAILED";

    // SHOW WHAT CAME BACK
    echo htmlentities($htm);
}


// END OF PHP PROCESSING - DROP INTO HTML TO PUT UP THE FORM
?>
ENTER THE PHONE NUMBER LIKE "004477909999"
<form>
<input name="d" value="<?php echo $dat; ?>" />
<input type="submit" />
</form>

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35069322
Sidebar note... Not sure if you're responsible for standards compliance, but this is worth a look.  My colleagues are telling me that standards are more and more important every day, especially in mobile apps.
http://validator.w3.org/check?uri=https%3A%2F%2Fwww.ecocaller.com%2F&charset=%28detect+automatically%29&doctype=Inline&group=0
0
 

Author Comment

by:daz1234
ID: 35069891
Hi Ray

can you send me a copy of your RAY_temp_daz1234.php as its failing everytime on my side

now i have access to the host files
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35070429
Use the code snippet at ID:35069308.  That is EXACTLY what is showing at this URL.
http://www.laprbass.com/RAY_temp_daz1234.php?d=004477909999
0
 

Author Comment

by:daz1234
ID: 35070703
can you test from your side my script

https://www.ecocaller.com/testchecker5.php
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35077881
Please post the code for your script, thanks.  When I run it I get this message:
WEB SERVICE AT https://www.ecocaller.com/secure/ratewebsite.aspx?dialplan=004477909999 FAILED

That is not what you want, but the answer may be really simple.  As I wrote above, If that [failure] is the case, get a new host.
0
 

Author Comment

by:daz1234
ID: 35080224
Do you think it's a configuration on the iis stopping it from working
0
 

Author Comment

by:daz1234
ID: 35082908
copy of file

<?php // testchecker5.php
error_reporting(E_ALL);


// FROM THE ORIGINAL POST AT EE
// rwebsite.aspx?dialplan=004477909999


// THE FULLY QUALIFIED URL OF THE WEB SERVICE WE WANT TO TALK TO
$url = 'https://www.ecocaller.com/secure/ratewebsite.aspx?dialplan=';

// DEFAULT VALUES ARE EMPTY
$dat = NULL;

// IF THERE IS DATA CALL THE WEB SERVICE
if (!empty($_GET["d"]))
{
    $dat = $_GET["d"];
    $url = $url . $dat;
    $htm = file_get_contents($url);

    if (!$htm) echo "<br/>WEB SERVICE AT $url FAILED<br/>";

    // SHOW WHAT CAME BACK
    echo htmlentities($htm);
}


// END OF PHP PROCESSING - DROP INTO HTML TO PUT UP THE FORM
?>
<html><body>
ENTER THE PHONE NUMBER LIKE "004477909999"
<form>
<input name="d" value="<?php echo $dat; ?>" />
<input type="submit" />
</form>
</body></html>
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35086762
Please explain how you solved this problem instead of deleting it, thanks.
0
 

Author Comment

by:daz1234
ID: 35087369
I was deleting a different question

Did I delete this one

I'm bad
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35087373
No prob - stuff happens.
0
 

Author Comment

by:daz1234
ID: 35087544
I still can't figure out why I can't run it on my side
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35090451
Let me try this question one last time before I sign off and recommend you stop work and hire a professional:  From ID:35069308... Where is ecocaller.com hosted?
0
 

Author Comment

by:daz1234
ID: 35092591
I think the problem is that if I am running the script from on the same server directory its the URL the issue
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35095560
Again: From ID:35069308... Where is ecocaller.com hosted?
0
 

Author Comment

by:daz1234
ID: 35095666
because you can access the command from external its a routing hosting issue

how would you set the url to take from within the same directory on the website
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35095855
What is so hard about answering my simple question?  Please help me help you.  For the last time, Again: From ID:35069308... Where is ecocaller.com hosted?
0
 

Author Comment

by:daz1234
ID: 35095875
its hosted on my servers isp verizon
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35095926
Thank you.  Is it a dedicated server or a shared server?
0
 

Author Comment

by:daz1234
ID: 35095973
dedicated
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35097756
Good.  Please install this little script and post a link to it here.  You can take it down after we get a chance to look at the settings.
<?php phpinfo();

Open in new window

0
 

Author Comment

by:daz1234
ID: 35130269
0
 

Author Comment

by:daz1234
ID: 35130270
sorry for not getting back sooner
0
 

Author Comment

by:daz1234
ID: 35130291
i can run your script from another physical server location and it works fine

when i run locally it doesn't
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 35138383
It looks like all requests to http are redirected to https.  That redirect might somehow be causing the problem, but I doubt it.  I do not see anything in the PHP Core that would cause file_get_contents() to fail.

We can use CURL - it might be able to get more diagnostic information.  This script works on my server at this URL:
http://www.laprbass.com/RAY_temp_daz1234.php
<?php // RAY_temp_daz1234.php
error_reporting(E_ALL);



// A FUNCTION TO RUN A CURL-GET CLIENT CALL TO A FOREIGN SERVER
function my_curl
( $url
, $get_array=array()
, $timeout=3
, $error_report=TRUE
)
{
    // PREPARE THE ARGUMENT STRING IF NEEDED
    $get_string = '';
    foreach ($get_array as $key => $val)
    {
        $get_string .= urlencode($key) . '=' . urlencode($val) . '&';
    }
    $get_string = rtrim($get_string, '&');
    if (!empty($get_string)) $url .= '?' . $get_string;

    $curl = curl_init();

    // HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
    $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE BLANK

    // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
    curl_setopt( $curl, CURLOPT_URL,            $url  );
    curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'  );
    curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
    curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
    curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );

    // RUN THE CURL REQUEST AND GET THE RESULTS
    $htm = curl_exec($curl);

    // ON FAILURE HANDLE ERROR MESSAGE
    if ($htm === FALSE)
    {
        if ($error_report)
        {
            $err = curl_errno($curl);
            $inf = curl_getinfo($curl);
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            var_dump($inf);
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS RETURN XML / HTML STRING
    curl_close($curl);
    return $htm;
}




// USAGE EXAMPLE - PUT YOUR FAVORITE URL HERE
$url = "https://www.ecocaller.com/secure/ratewebsite.aspx";

// PUT YOUR ARRAY OF KEY=>VALUE PAIRS HERE
$arg = array
( 'dialplan' => '004477909999'
)
;

// MAKE OUTPUT EASY TO READ
echo "<pre>";

// MAKE THE CALL
$htm = my_curl($url, $arg, 5, TRUE);
if (!$htm) die("NO $url");

// SHOW WHAT WE GOT
var_dump($arg);
echo PHP_EOL . $url;
echo PHP_EOL . htmlentities($htm);
echo PHP_EOL;

Open in new window

0
 

Author Comment

by:daz1234
ID: 35139348
CURL FAIL: https://www.ecocaller.com/secure/ratewebsite.aspx?dialplan=004477909999 TIMEOUT=5, CURL_ERRNO=28array(20) {
  ["url"]=>
  string(71) "https://www.ecocaller.com/secure/ratewebsite.aspx?dialplan=004477909999"
  ["content_type"]=>
  NULL
  ["http_code"]=>
  int(0)
  ["header_size"]=>
  int(0)
  ["request_size"]=>
  int(0)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0)
  ["namelookup_time"]=>
  float(0)
  ["connect_time"]=>
  float(0)
  ["pretransfer_time"]=>
  float(0)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(-1)
  ["upload_content_length"]=>
  float(-1)
  ["starttransfer_time"]=>
  float(0)
  ["redirect_time"]=>
  float(0)
}
NO https://www.ecocaller.com/secure/ratewebsite.aspx
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35139821
Please see this page.
http://curl.haxx.se/libcurl/c/libcurl-errors.html

CURL error #28 is a timeout.  Consider raising the timeout parameter, maybe to 15 or 20, to see if the script has time to respond.  

If that does not work, then I have to expect that something in /secure/ratewebsite.aspx is deliberately reacting differently to calls from local and remote URLs.   I would never design a program that way, but maybe someone did?
0
 

Author Comment

by:daz1234
ID: 35139856
iis for ecocaller domain is redirecting

port 80 to port 81 with forced SSL could that be the cause
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35139936
Why?  How does that help things?
0
 

Author Comment

by:daz1234
ID: 35139969
its was configured that way because of IIS 6

to redirect all normal http to https
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35140112
But is there some reason for doing that?  Why not use the protocol that is requested by the client?  That would seen to make sense to me.

Regarding ID:35139821 -- did you try a longer timeout?
0
 

Author Comment

by:daz1234
ID: 35140448
no difference still timeout same error
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35140671
Then I have to expect that something in /secure/ratewebsite.aspx is deliberately reacting differently to calls from local and remote URLs.  I think we have exhausted what we can do without seeing that script.  Suggest you post a new question in the ASP Zone with the source code for that script.  You would probably want to post a link to this question, too, so anyone seeing the new question can see what we have pursued on this side.
0
 

Author Comment

by:daz1234
ID: 35140692
thanks for all your effort and help
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35141698
You're welcome.  It will be interesting to see what that script is doing differently when it encounters different clients!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question