Reputation: 31637
I am newbie for iPhone application. I have followed this tutorial for login from iPhone.
I have php file as below.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
$user = $_POST['uname'];
if ($user == 'user') {
echo "Welcome to my site...";
} else {
echo "Invalid User";
}
?>
</body>
</html>
When I run application and enter username as user and password as some text, I get output in iPhone as below
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
Welcome to my site...
</body>
</html>
The output that I was expecting is only text Welcome to my site..., however I get full HTML code.
Any idea why I get like this? What changes do I have to need to do in PHP file?
Upvotes: 0
Views: 87
Reputation: 4520
Your php server prints out anything AS IS, as long as it is not in a php block
<?php
//this is interpreted php code
?>
So it prints out everything html in the file until it reaches a php block of code. It interprets what is in the php block and inserts what you echo at that position of the file. When the php block ends it just spits out everything that follows again - as html in your case.
If you want just the simple text output, you have to leave out the HTML (which is not necessary to make the php work).
If on the other hand, you need the HTML for having access to the site via a web browser too, you better put your evaluation php in a separate php file and point your iPhone app to just this php file. In your HTML file you include this ile via the php require function.
Upvotes: 0
Reputation: 899
Your php script will output all the Text what you write in the File.
Bevore and after the PHP tag you wrote a HTML Header, Body. Try to remove this:
<?php
$user = $_POST['uname'];
if ($user == 'user') {
echo "Welcome to my site...";
} else {
echo "Invalid User";
}
?>
But if you try to login a User and then Interact later with the Server, without passing always the User, then Send to the Server the Username, like you did, create a Session, save the User and pass a unique Session ID back to the iPhone. Then when you connect the next time to the API, you know already the user, and you don't have to revalidate if he is logged in.
Upvotes: 0
Reputation: 3108
as per the iphone application development tutorial they are using standard sdk for creating buttons and text boxes it is not html, if you want to create your login form using html in iphone use webView, as you are printing full html code it is showing your that only, put only following code in your index.php file
<?php
$user = $_POST['uname'];
if ($user == 'user') {
echo "Welcome to my site...";
} else {
echo "Invalid User";
}
?>
Upvotes: 2