• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

get url

The following code gets a url date from a previous page
The date format sent is fine
$dte = $_GET[sourcedte];

I am trying to create a forwarding url and I am using he following to recreate the date but it doe not work correctly - I only get F in the url

$sourcedate = "&sourcedte=date('F j, Y g:ia',$dte)";

Any ideas anyone ?
0
doctorbill
Asked:
doctorbill
  • 9
  • 8
  • 4
  • +1
2 Solutions
 
GaryCommented:
$dte = $_GET['sourcedte'];
0
 
doctorbillAuthor Commented:
Tried that:
I only get "September" in the built url
0
 
GaryCommented:
Do an
echo $_GET['sourcedte'];
and paste the results here
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
doctorbillAuthor Commented:
September 27, 2012 7:46pm
0
 
GaryCommented:
What are you trying to do here

$sourcedate = "&sourcedte=date('F j, Y g:ia',$dte)";

based on the data you would end up with

"&sourcedte=date('F j, Y g:ia',September 27, 2012 7:46pm)"

If you are trying to convert the date then what is the point as it would be exactly the same format as what you have posted above.
0
 
Dave BaldwinFixer of ProblemsCommented:
The PHP 'date' function expects a timestamp for the second parameter and that's not what you're getting in $dte.  This can't work:

$sourcedate = "&sourcedte=date('F j, Y g:ia',$dte)";

However all you really need to do is 'urlencode' $dte and concatenate it to the new URL.

$URLstring = $newurl  . urlencode($dte);
0
 
doctorbillAuthor Commented:
This is my redirect url:

$url = "orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1$red$pldte2.urlencode($dte)";

Still not working
0
 
doctorbillAuthor Commented:
0
 
GaryCommented:
$url = "orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1$red$pldte2&sourcedte=".$_GET['sourcedte'];
0
 
Dave BaldwinFixer of ProblemsCommented:
Does it work in your browser if you make everything literal?  Everything after '?p=' should be urlencoded.  You can not put a normal page address there and have it work.  The '//' and all '/' must be url encoded also.  In addition, I don't think you can concatenate that way.  Putting the 'urlencode' inside the string that way won't work because it won't be recognized as a function.  I'd try something like this:

$dteenc = urlencode($dte);
$newurl = urlencode($red$pldte2);
$url = "orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1".$newurl.$dteenc;

Open in new window

0
 
doctorbillAuthor Commented:
I now get this:

Error in my_thread_global_end(): 1 threads didn't exit PHP Parse error: syntax error, unexpected '"' in I:\CommercialWebsites\1callorders\site\orders_find_visit_print_custom_status_noforms_nocosts_idfilter2.php on line 37
0
 
Dave BaldwinFixer of ProblemsCommented:
That's not the same URL you have been posting.

orders_find_visit_print_custom_status_noforms_nocosts_idfilter2.php

orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php
0
 
doctorbillAuthor Commented:
The one I just pasted is the url which is the one I am trying to build as a redirect from the GET command
0
 
GaryCommented:
$newurl = urlencode($red$pldte2);

Cannot encode them, the string is already built.

Did you try
$url = "orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1$red$pldte2&sourcedte=".$_GET['sourcedte'];
0
 
doctorbillAuthor Commented:
This is the latest redirect code in my page:

$url = "orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1$red$pldte2&sourcedte=".$_GET['sourcedte'];

This is the resultant url sent using the above code:
http://localhost/comwebsites/1callorders/site/orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1&ID[78]&ID[79]&pldte=126&sourcedte=September
0
 
GaryCommented:
What is your code for the redirect?
0
 
GaryCommented:
$url = "orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1$red$pldte2&sourcedte=".urlencode($_GET['sourcedte']);
0
 
Dave BaldwinFixer of ProblemsCommented:
The spaces and the square brackets must be urlencoded.  Note that only the 'data' after the '=' and before the '&' is what should be encoded.

In addition, you will find that "&ID[78]&ID[79]" will probably not work as expected because they are not "name/value" pairs that PHP is expecting.  The expected format is "&name=value" except for the first one which starts with the "?p=1".

http://en.wikipedia.org/wiki/Percent-encoding
0
 
doctorbillAuthor Commented:
Managed to sort it:

$dte = urlencode($_GET['sourcedte']);
$sourcedate = "&sourcedte=$dte";

This is the redirect code which now works:
$url = "orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1$red$pldte2$sourcedate";

URL sent from above code:
http://localhost/comwebsites/1callorders/site/orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1&ID[78]&ID[79]&pldte=126&sourcedte=September+27%2C+2012+7%3A46pm
0
 
Ray PaseurCommented:
I think you will find that urlencode() is needed on each item of the URL string, separately.  This includes both the keys and the values, unless you're creating arrays in the request, then the array key and data must be urlencoded, too.  Then once that is done you can assemble the request string starting with the ? and separated by the &.

Not all characters are affected by urlencode().

A blank in the GET request that is not urlencoded to a + or %20 tells the browser that it has come to the end of the request string.
0
 
doctorbillAuthor Commented:
thanks for all the input
0
 
GaryCommented:
You accept a comment posted after it is fixed and ignore everything I posted?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 8
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now