?
Solved

Ajax and PHP - Alternative to "echo"

Posted on 2014-03-12
2
Medium Priority
?
899 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
[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
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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

741 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