Solved

How to create ASHX page in ASP.NET alike but using PHP page

Posted on 2014-09-26
7
366 Views
Last Modified: 2014-09-26
Hello
I am new to php, I wish to create a page that response to client similar to ashx page in asp.net

how to make php return very simple text to client when request something var http.

Any idea and place for me to start?
0
Comment
Question by:JSW21
7 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 167 total points
ID: 40345551
Do you have PHP installed on your web server?  Probably the simplest possible PHP page would be:
<?php
echo "This is the text from the PHP page";
?>

Open in new window

Save it to a file on your web server called somthing like 'simpleecho.php'.  Then put it in your browser address bar with the server name like "http://10.10.10.10/simpleecho.php" and you should see the text.
0
 
LVL 30

Assisted Solution

by:Alexandre Simões
Alexandre Simões earned 166 total points
ID: 40345570
ASHX are like WebPages but with a shorter pipe line.

I know nothing about PHP but what he wants is a way to call a server-side PHP method via HTTP verbs and receive a response in the requested content type.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40345573
Maybe this can give you a head start :)

http://www.w3schools.com/php/php_ajax_php.asp
http://www.tutorialspoint.com/php/php_and_ajax.htm

sorry for the links mate, like I told before, PHP is not in my toolbox :)
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40345592
All page links are GET method.  You have to use a form to use POST and some kind of program (like cURL) to use PUT.  http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
0
 
LVL 54

Assisted Solution

by:Julian Hansen
Julian Hansen earned 167 total points
ID: 40345609
PHP by default acts on a more basic level than ashx page. You have to specifically code the PHP page to respond to the type of request you want to make.

You want to retrieve some text - example script returns the sum of two numbers.

simpleadd.php?a=5&b=6

PHP
<?php
// Get sanitised input - expecting two parameters of type int 
// so make sure that is what you get

$a = isset($_GET['a']) ? (int)$_GET['a'] : 0;
$b = isset($_GET['b']) ? (int)$_GET['b'] : 0;

echo $a + $b;

Open in new window


Other means of returning parameters $_POST (for posted data) $_REQUEST for data in both GET and POST

If you want to return different mimetypes you need to specifically set this with the header() function (before you send any output)
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40345614
Dave, I was speaking about Ajax calls there... :)

ASHXs are a very good option the handle Ajax calls in the .Net world. In fact they are a much better option than the webmethods although they require a bit more work.
0
 

Author Closing Comment

by:JSW21
ID: 40345672
Thanks, guys.
I tested the code and "echo" is all i need to achieve ashx page alike - no html tag etc.

Bests to all.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

785 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