Solved

get url

Posted on 2014-01-18
23
424 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
Comment Utility
$dte = $_GET['sourcedte'];
0
 

Author Comment

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

Expert Comment

by:Gary
Comment Utility
Do an
echo $_GET['sourcedte'];
and paste the results here
0
 

Author Comment

by:doctorbill
Comment Utility
September 27, 2012 7:46pm
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
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 82

Accepted Solution

by:
Dave Baldwin earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 58

Expert Comment

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

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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
Comment Utility
$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
Comment Utility
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
Comment Utility
What is your code for the redirect?
0
 
LVL 58

Expert Comment

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

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks for all the input
0
 
LVL 58

Expert Comment

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

772 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

10 Experts available now in Live!

Get 1:1 Help Now