Solved

get url

Posted on 2014-01-18
23
429 Views
Last Modified: 2014-01-19
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
Comment
Question by:doctorbill
  • 9
  • 8
  • 4
  • +1
23 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39790846
$dte = $_GET['sourcedte'];
0
 

Author Comment

by:doctorbill
ID: 39790912
Tried that:
I only get "September" in the built url
0
 
LVL 58

Expert Comment

by:Gary
ID: 39790920
Do an
echo $_GET['sourcedte'];
and paste the results here
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:doctorbill
ID: 39790935
September 27, 2012 7:46pm
0
 
LVL 58

Expert Comment

by:Gary
ID: 39790946
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
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 39790947
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
 

Author Comment

by:doctorbill
ID: 39790961
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
 

Author Comment

by:doctorbill
ID: 39790965
0
 
LVL 58

Expert Comment

by:Gary
ID: 39790973
$url = "orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1$red$pldte2&sourcedte=".$_GET['sourcedte'];
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39790977
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
 

Author Comment

by:doctorbill
ID: 39790992
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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39790997
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
 

Author Comment

by:doctorbill
ID: 39791004
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
 
LVL 58

Expert Comment

by:Gary
ID: 39791009
$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
 

Author Comment

by:doctorbill
ID: 39791021
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
 
LVL 58

Expert Comment

by:Gary
ID: 39791044
What is your code for the redirect?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39791056
$url = "orders_find_visit_print_custom_status_noforms_nocosts_idfilter2_ReadOnly2.php?p=1$red$pldte2&sourcedte=".urlencode($_GET['sourcedte']);
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39791057
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
 

Author Comment

by:doctorbill
ID: 39791080
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
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39791100
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
 

Author Closing Comment

by:doctorbill
ID: 39791108
thanks for all the input
0
 
LVL 58

Expert Comment

by:Gary
ID: 39791114
You accept a comment posted after it is fixed and ignore everything I posted?
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 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