...

View Full Version : Posting to a URL



tb582
08-27-2009, 02:29 PM
I have an application that posts to a URL whenevery X Y or Z happens. This URL is very crude.

accountname=testaccount&action=Add&actionDate=2005-04-30T01:02:49.760Z&IDs=1234567&itemType=Media&titles =testfile&userEmail=test@test.com&userID=9998767

So basicly what this says is that user test added a file to testaccount and the date that this took place as well as the title of that file. This URL is not very pretty to look at, whats my best way to clean this up so that it is more pleasing to the eye? is that possible with PHP?

I also have the ability to use an JSP page, a PHP page, a CGI script, a .NET application, or any other web application that can be invoked from a URL.

My second issue is that I have multiple "accounts" that either need to post to a seperate page OR to the same page but again this would have to be much easier to read than the current URL that I get back.



So instead of getting back: accountname=testaccount&action=Add&actionDate=2005-04-30T01:02:49.760Z&IDs=1234567&itemType=Media&titles =testfile&userEmail=test@test.com&userID=9998767

I would rather see:

Account Name: Testaccount
Action: Add
Action Date:
ID's:
ItemType: Media
Title: Testfile
UserEmail: test@test.com
UserID: 9998767

Ideally I'm imagining output like the one above that does two things one that gets emailed to those that I specify and two is that its also displayed on the .php page.

tomws
08-27-2009, 03:26 PM
I'm confused about your problem. It looks like all you have is a simple GET query string. PHP can handle that easily just by using $_GET - standard form handling. If you don't want it in the URL, use POST instead, and then use the PHP $_POST variable. Then manipulate your data however you want.

tb582
08-27-2009, 08:37 PM
Sorry I'm not really a programmer - was looking more for "use this code" - I had asked over at the ASP message boards http://www.aspmessageboard.com/showthread.php?t=232309 - but in the end figured out that the web server I'm using doesn't support asp...

whizard
08-27-2009, 08:42 PM
Where would you rather see that output?

Dan

tb582
08-27-2009, 09:42 PM
I would like the output in two places, one is on a webpage and two is for it to get emailed. Both should be in the following format:

Account Name: Testaccount
Action: Add
Action Date:
ID's:
ItemType: Media
Title: Testfile
UserEmail: test@test.com
UserID: 9998767

tb582
08-31-2009, 01:45 AM
I would like the output in two places, one is on a webpage and two is for it to get emailed. Both should be in the following format:

Account Name: Testaccount
Action: Add
Action Date:
ID's:
ItemType: Media
Title: Testfile
UserEmail: test@test.com
UserID: 9998767

Can anyone provide me with the code?

Scriptet
08-31-2009, 01:51 AM
How are you submitting the data to the PHP page in the first place, via a form of some sort?
As explained earlier it would seem like it's being sent via the get method, when post is really what you are looking for.

So
1. How are you submitting the data
2. If you can post up the .php file that recieves the data

then i or someone can post up a solution!

tb582
08-31-2009, 02:01 AM
How are you submitting the data to the PHP page in the first place, via a form of some sort?
As explained earlier it would seem like it's being sent via the get method, when post is really what you are looking for.

So
1. How are you submitting the data
2. If you can post up the .php file that recieves the data

then i or someone can post up a solution!

The data is coming from a program that I give it a URL to "post" to. So whenevery X Y or Z happens. It will post the follwing to the URL given:

accountname=testaccount&action=Add&actionDate=2005-04-30T01:02:49.760Z&IDs=1234567&itemType=Media&titles =testfile&userEmail=test@test.com&userID=9998767

I just want two thing, one to make the above presentable and two is to have the same presentable version emailed.

Scriptet
08-31-2009, 02:14 AM
OK Well you didn't really answer either of my questions...but anyway

Here is how to obtain data from a URL in PHP:
A page with the following URL:
mysite.com/mypage.php?accountname=testaccount&action=Add&actionDate=2005-04-30T01:02:49.760Z&IDs=1234567&itemType=Media&titles =testfile&userEmail=test@test.com&userID=9998767

Then mypage.php would be:


<html>
<head>
</head>
<body>
<?php
$accountname = $_GET['accountname'];
$action = $_GET['action'];
$actionDate = $_GET['actionDate'];
$IDs = $_GET['IDs'];
$itemType = $_GET['itemType'];
$titles = $_GET['titles'];
$userEmail = $_GET['userEmail'];
$userID = $_GET['userID'];

echo "Account Name: ".$accountname."<br />";
echo "Action: ".$action."<br />";
echo "Action Date: ".$actiondate."<br />";
echo "IDs: ".$IDs."<br />";
echo "Item Type: ".$itemtype."<br />";
echo "Title: ".$titles."<br />";
echo "User Email: ".$userEmail."<br />";
echo "User ID: ".$userID."<br />";
?>
</body>
</html>


This would output the information on the screen. You can then proceed to email this information, just check that this works first.

If you were on about making the URL pretty then you'd have to submit the data via a form rather than using the URL.

tb582
08-31-2009, 02:02 PM
Thanks,

So with that code, formatting is correct but I do not see any output. Is there any debugging that can be added to see what if any values are trying to be posted?

Scriptet
08-31-2009, 02:11 PM
Try this:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
if($_GET){
echo "The Contents of the $_GET array are shown below:";
//Loop through get array
foreach($_GET as $key => $value){
$num++;
echo $num." Key: ".$key." Value: ".$value."<br />";
}

$accountname = $_GET['accountname'];
$action = $_GET['action'];
$actionDate = $_GET['actionDate'];
$IDs = $_GET['IDs'];
$itemType = $_GET['itemType'];
$titles = $_GET['titles'];
$userEmail = $_GET['userEmail'];
$userID = $_GET['userID'];

echo "Account Name: ".$accountname."<br />";
echo "Action: ".$action."<br />";
echo "Action Date: ".$actiondate."<br />";
echo "IDs: ".$IDs."<br />";
echo "Item Type: ".$itemtype."<br />";
echo "Title: ".$titles."<br />";
echo "User Email: ".$userEmail."<br />";
echo "User ID: ".$userID."<br />";
}
else{
echo "<h1>No Values were found in the $_GET Array!</h1>";
}
?>

</body>
</html>

tb582
08-31-2009, 02:31 PM
No Values were found in the Array Array! hmmm

Scriptet
08-31-2009, 02:46 PM
I just tested it myself and it works, copy and paste the URL of the page you are getting this message.

It should be like this:

mysite.com/mypage.php?accountname=testaccount&action=Add&actionDate=2005-04-30T01:02:49.760Z&IDs=1234567&itemType=Media&titles =testfile&userEmail=test@test.com&userID=9998767

tb582
08-31-2009, 02:49 PM
2009-08-31 06:13:15,173 [SendNotification30815[130983018]] Posting to http://mysite.com/testing.php with data account=testaccount&action=Modify&actionDate=2009-08-31T13%3a13%3a15.543Z&IDs=562158454&titles=this is a test&server=http://testserver.com&statusValues=OK&previousStatusValues=Error&itemType=Media&userEmail=test_test%40mysite.com&userID=5621548645

Scriptet
08-31-2009, 03:14 PM
What is that, i'm assuming instead of mysite.com you have your URL there in reality.

When it says with data etc.. how exactly is it sending this data?

For what I have done to work it would need to post it like this:


http://mysite.com/testing.php?account=testaccount&action=Modify&actionDate=2009-08-31T13%3a13%3a15.543Z&IDs=562158454&titles=this is a test&server=http://testserver.com&statusValues=OK&previousStatusValues=Error&itemType=Media&userEmail=test_test%40mysit e.com&userID=5621548645

Note all the data comes after a question mark in the URL

tb582
09-01-2009, 01:47 PM
ok was able to get some more details from the software vendor.... its being sent via an HTTP post. So does that mean I need to change ALL of the _GETs to _POST ? Anything else I need to do?

tb582
09-01-2009, 03:06 PM
Actually in order to test that the notification was successful, can I log something to a file rather than print to the screen?

tomws
09-01-2009, 03:29 PM
Yes: fopen (http://php.net/fopen), fwrite (http://php.net/fwrite)

tb582
09-01-2009, 04:09 PM
Yes: fopen (http://php.net/fopen), fwrite (http://php.net/fwrite)

Not sure how I would implement this into the code that Scriptet gave.

tomws
09-01-2009, 04:11 PM
You would implement it by using fopen to open a file and fwrite to write to the file. The documentation is clear and the examples are probably sufficient for your purpose.

tb582
09-01-2009, 05:12 PM
I've gone back to using the code below - I'm not seeing anything work either with this code or with the code using the IF statement.


<html>
<head>
</head>
<body>
<?php
$accountname = $_GET['accountname'];
$action = $_GET['action'];
$actionDate = $_GET['actionDate'];
$IDs = $_GET['IDs'];
$itemType = $_GET['itemType'];
$titles = $_GET['titles'];
$userEmail = $_GET['userEmail'];
$userID = $_GET['userID'];

echo "Account Name: ".$accountname."<br />";
echo "Action: ".$action."<br />";
echo "Action Date: ".$actiondate."<br />";
echo "IDs: ".$IDs."<br />";
echo "Item Type: ".$itemtype."<br />";
echo "Title: ".$titles."<br />";
echo "User Email: ".$userEmail."<br />";
echo "User ID: ".$userID."<br />";
?>
</body>
</html>

tomws
09-01-2009, 05:25 PM
POSTed information is retrieved through $_POST, not $_GET. Try changing those first.


$accountname = $_POST['accountname'];

tb582
09-01-2009, 05:51 PM
POSTed information is retrieved through $_POST, not $_GET. Try changing those first.


$accountname = $_POST['accountname'];

Still nothing, new code:


<html>
<head>
</head>
<body>
<?php
$account = $_POST['account'];
$action = $_POST['action'];
$actionDate = $_POST['actionDate'];
$IDs = $_POST['IDs'];
$itemType = $_POST['itemType'];
$titles = $_POST['titles'];
$userEmail = $_POST['userEmail'];
$userID = $_POST['userID'];

echo "Account Name: ".$account."<br />";
echo "Action: ".$action."<br />";
echo "Action Date: ".$actiondate."<br />";
echo "IDs: ".$IDs."<br />";
echo "Item Type: ".$itemtype."<br />";
echo "Title: ".$titles."<br />";
echo "User Email: ".$userEmail."<br />";
echo "User ID: ".$userID."<br />";
?>
</body>
</html>

tomws
09-01-2009, 08:55 PM
What app or web service are you trying to use?

tb582
09-02-2009, 02:49 AM
I would actually like to try writing the post to a file - can someone post the code that will do this?

Scriptet
09-02-2009, 08:31 PM
Hi,

Just try something like this first:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
if($_POST){
echo "<h1>There is Post Data being sent to this file</h1>";
}
else if($_GET){
echo "<h1>There is Get Data being sent to this file</h1>";
}
else {
echo "<h1>There is no POST or GET data being sent to this file</h1>";
}
?>
</body>
</html>

to see if we are getting any data sent to the file via POST or GET



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum