Solved

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

Posted on 2014-09-26
7
360 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to count occurrences of each item in an array.

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now