Calling a method form a mobile application [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm new with PHP.
In my mobile application I have to query some data form server.
I have to call login before i can access the data.
I have to use the following type of Post request
http://SERVER_IP/wapdb/smartphone_login/
How it can be done in my PHP file?
Thanks,
Eyal.

I think you should detect the mobile device after the login so the webpage/mobile application uses styling that would work for maybe the desktop and mobile but when you login, it logs in the same way you would on a desktop using PHP, after you login, you could then change the page contents by the resolution of the phone. Otherwise you end up having two potentially dangerous logins that are basically the same but different folders.
In the form you will have used the method post, so the PHP script will use an array called $_POST and can use it by the name of the input elements for example (example in HTML):
<form method='POST' action='test.php'>
<input name='first_name'/>
<input type='submit' value='Send'/>
</form>
In PHP you can then do whatever you want by reading the contents of the post array
<?php
echo "Your name is " . $_POST['first_name'];
?>
You can use a php file to add the server IP in a tag.
<?php echo "<form method='POST' action='http://" . $_SERVER['SERVER_ADDR'] . "/wapdb/login/'><input name='first_name'/><input type='submit' value='Send'/></form>"; ?>
I would recommend you to have a play with $_SERVER["SERVER_NAME"] and other variables from http://php.net/manual/en/reserved.variables.server.php since it might use the internal IP address and you'd want the public IP. You can also look at some information available at W3Schools. http://www.w3schools.com/php/php_forms.asp
Hope this helps.

Related

Any Site That Displays The Received Text? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
So pretty much what I am looking for is a site that simply accepts POST requests, and the site then just displays the text received from the POST request.
For example, lets say that I POSTed "Hello, world!" to the site, if I looked at the contents of the page, it just said "Hello, world!". I need this for testing/developing purposes.
If not, could somebody possibly create a PHP script for this? I don't know PHP, otherwise I would do it myself :)
Thanks
EDIT: Sorry for the extremely easy question, I didn't realise it was this easy. Thanks for the answers :)
<?php
header("Content-Type: text/plain");
print_r($_POST);
This uses print_r to dump the content of the $_POST array. The page content type of text/plain is needed to prevent creating an XSS vulnerability.
Try this
First create a file names mypage.php then save this code.
<?php
if(isset($_POST['myText']))
{
echo $_POST['myText']
}
<form action='mypage.php'>
<input type='text' name='myText'>
<input type='submit'>
</form>
?>
Assume your form looks like this
<form method="POST">
<input type='text' name='field'>
<input type='submit' value='Submit'>
</form>
The simplest way is write this code below it
<?php var_export($_POST); ?>
Write your own! Do this on any website you have
Simply print_r($_POST); should suffice on a blank page

How do I increment a variable in PHP when an href link is clicked [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want $counter=$counter +1, when this link on my website is clicked:
<img src="images/old.jpg" width="190" height="32" />
I've tried $counter++; in several creative ways, none of which seem to have worked.
PHP is a server-side language.
This means that PHP is (most often) only responsible from
When the server receives a request
until
The PHP program outputs the page.
So if you want something to happen in response to your action AFTER the page is loaded (e.g. clicking a link), PHP cannot handle that.
Now, you should choose your implementation in either Javascript or PHP depending on what you want to achieve.
If you want to store the counter value in your server, and increment it:
Set the destination of the link to the exactly same page as the one you are viewing now. Use $_SESSION to store a value, and it will be stored across multiple requests.
If you want to see the value of the counter go up as you click on the link:
Use Javascript to store the counter as an variable, and increment it on each click. This will be reset if you refresh the page.
Note: You cannot achieve neither of this if your link takes you to another page. That becomes a whole new story.

Passing data from html server (with no php) to server with PHP and return data to that non-php server [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Here's the deal:
I have blog, where I can only use a javascript and free php server. I need to send form data to that php server (this I know how to do), and return some info back to the blog page. Is that even possible?
The only way I can think with out cross domain request is as below
1) make this form in your blog
<form action="FULL_URL_TO_YOUR_PHP_FILE">
/// your fields
</form>
2) in your php file save data received from form and serialize the data(that you want to send back to your blog) in url format like
if you want to pass name and surname YOUR_BLOG_URL?name=myName&surname=MySurname and make redirect from your php file to your blog
header('location:YOUR_BLOG_URL?name=myName&surname=MySurname');exit;
3) now on your blog make an onload event like if you have jquery than
$(document).ready(function(){
alert(window.location.href);
// do some spliting or regexp or anything else to get your data from url
})

Passing data from HTML page to PHP script [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So I currently have a PHP script that is being called from an HTML link. The script is set up such that it needs to accept non-user input from the page (static data that already exists). The line that calls the script looks like this.
<div class="Name">Text</div>
I need to pass the values in "Name" and Text to the script, as well as another value from an earlier line.
What would be the best way to accomplish this? All of my research points to using forms and GET/POST, but as you can see, there is no place for the user to input any of the data. Is there any way to do this using hidden forms or AJAX?
If you're the author of the web page, you'd use javascript and an onclick event to capture the div class and the anchor's text, and send it via ajax (or directly if your script provides some sort of user output or redirect back to the calling page) to your script as a post event. the data could be conveniently formatted as a json structure to simplify the script's processing.
By using the GET method :
<div class="Name">Text</div>
Maybe this code well help
<div class="Name"><a id="link" href="some/script.php">Text</a></div>
<input id="name" onblur="modify(this.value)">
<script type="text/javascript">
var link = document.getElementById("link").href;
var modify = function(name){
var a = document.getElementById("link");
a.href = link + "?name="+name;
}
</script>
In the href attribute for the link, do something like this:
href="some/script?name=George&text=All This Stuff"
This will make the information available in the $_GET[] array in the PHP script.

How can I store data from MySQL into html using php? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This is something I need help on.
Im going to allow a user from my database to "share" a record which gets sent from the database into a solid html file.
So I'm looking at ways to create a html file from data in a database which is passed through php and stored in a location on the server. with no interaction from the user at all other than pressing 'share'. They would be sent the url to look at it upon success.
I'm looking for any functions or tuts on how to best make a html file from php. any help is appreciated. I think I may be looking into this too much, and the answer may be staring me in the face
As it got clear, you want static html files, created dynamically via PHP and written on the server.
The steps you need to follow are clear too:
You need the database and as you said you have it
You need to connect to it via PHP
Then do the respective queries
Fetch the data from them
Use it in the HTML
Open a file
Send the used data to it
Write the file with the relevant name
The querying should start after the button share is clicked (you can track this via isset() function)

Categories