Solved

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

Posted on 2014-09-26
7
371 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 55

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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?
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
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…

861 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