?
Solved

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

Posted on 2014-09-26
7
Medium Priority
?
434 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
[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
7 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 668 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 664 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
Technology Partners: 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 84

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 59

Assisted Solution

by:Julian Hansen
Julian Hansen earned 668 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

719 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