Solved

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

Posted on 2014-09-26
7
353 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 82

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 82

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 51

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

759 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