Solved

get url

Posted on 2014-01-18
23
426 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 dynamically set the form action using jQuery.

912 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now