Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP Script Example That Allows Server-Side Calls

Posted on 2008-10-31
12
Medium Priority
?
223 Views
Last Modified: 2013-12-13
I'm looking for a php script that will let me do server-side calls. Does anyone have an example? Thanks!
0
Comment
Question by:deharvy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 6

Expert Comment

by:fourice
ID: 22851665
Maybe I'm missing something, but PHP is a server-side language...
Perhaps you mean something else?
0
 

Author Comment

by:deharvy
ID: 22851857
I am looking for a script that when a user goes to it, there will be a prompt to enter a URL and submit.   This will run on the serverside so as no firewall should block it.
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 22851860
Are you talking AJAX? There is an example of how to implement AJAX at http://www.experts-exchange.com/Q_23107627.html
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 22851891
daharvy:

Looks like we posted at the same time... fourice is right PHP is a server side language so no firewall can block it. Do you mean that you are looking for someone to write a PHP script for you to accept a URL?
0
 

Author Comment

by:deharvy
ID: 22852040
Well, yes... I'm looking for an example of a PHP script that will be used to accept a URL.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22856451
HTML and Javascript will do the trick...

If you want to do a PROXY CONNECTION to a website that is a whole different ballgame.

Save file as .html or .html
<html>
<head>Redirect to URL
</head>
<body>
<form name="zform" method="post" onsubmit="window.location = (('http://' + document.zform.zurl.value)); return false;">
http://<input type="text" name="zurl" />
<input type="submit">
</body>
</html>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22856453

<html>
<head>Redirect to URL
</head>
<body>
<form name="zform" method="post" onsubmit="window.location = (('http://' + document.zform.zurl.value)); return false;">
http://<input type="text" name="zurl" />
<input type="submit" value="Go">
</body>
</html>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22856455
Final version use this one the previous ones had incorrect heading.

Save as .html or .htm
<html>
<head>
<title>
Redirect to URL
</title>
</head>
<body>
<form name="zform" method="post" onsubmit="window.location = (('http://' + document.zform.zurl.value)); return false;">
http://<input type="text" name="zurl" />
<input type="submit" value="Go">
</body>
</html>

Open in new window

0
 

Author Comment

by:deharvy
ID: 22856627
Ok. Thanks. I'll test now.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22863275
I'm curious - what do you mean by "accept a URL" - do you mean that a client types in a URL and the script redirects to the URL?  Isn't that what the browser address bar does?  Or do you mean that a client types a URL and the action script accesses the URL, possibly passing along some GET or POST data?

&iquest; RSVP ?
0
 
LVL 19

Accepted Solution

by:
NerdsOfTech earned 1500 total points
ID: 22863623
You can use CURL via PHP to obtain the remote source and output it if that is your intention.

This code can be very useful to include, to get other data from another website, please take mind of COPYRIGHT laws, and always ask the website admin and/or ID (intellectual Data) Department if it is okay to use content from their website.

Basically just add the code below into a node, making sure that the Input Format is a PHP Page.

Source: http://drupal.org/node/325590
<?php
 
$curl_handle=curl_init();
//This is the URL you would like the content grabbed from
curl_setopt($curl_handle,CURLOPT_URL,'http://www.google.com');
//This is the amount of time in seconds until it times out, this is useful if the server you are requesting data from is down. This way you can offer a "sorry page"
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
 
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
//This Keeps everything running smoothly
curl_close($curl_handle);
 
// Change the message bellow as you wish, please keep in mind you must have your message within the " " Quotes.
if (empty($buffer))
{
    print "Extraction Failed";
}
else
{
    print $buffer;
}
?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22863806
You can also use $html = file_get_contents($url); This will also let you add URL arguments.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

721 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