[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Ajax and PHP - Alternative to "echo"

Posted on 2014-03-12
2
Medium Priority
?
981 Views
Last Modified: 2014-03-12
Hi E's, when I use ajax and php, usually I use php "echo" to send the information to ajax, like this examples:
ajax.php
$(function(){
        $.ajax({
        type: "POST",
        url: "index.php",
        data: {"anything":anydata},
        success: function(dat){
                if(dat == ""){
                    alert("empty");
                } else {
                alert(dat);
                } 
        }
        });
});

Open in new window

index.php
<? echo "some data"; ?>

Open in new window

In this case the ajax call will return "some data", and that is correct.
The problem is when the malicious customer/client execute directly index.php, in this case will appear in the screen "some data". Off course this is a simple example with no value data, but this is just a example.
So my question is, have any alternative to the php "echo" to send data between php and ajax, that malicious client cant see when execute directly the php files?

The best regards, JC
0
Comment
Question by:Pedro Chagas
  • 2
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39924797
Basically the answer is "no," but you may be able to embed some kind of signal or indicator in the application.  For example, you can check $_SERVER['HTTP_REFERER'].  And you can check to see that the request method is POST.

The "problem" you describe is actually a useful debugging feature; it lets us debug the background script without having to use the jQuery script at the same time.  The isolation of functionality helps make for faster problem identification!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39924923
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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)
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

831 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