is this one an issue?
// BUG or Wanted?
echo phpUri::parse('https://www.google.com/images/large')->join('animals/italy/tiger.jpg');
// RESULT
// => https://www.google.com/images/animals/italy/tiger.jpg
// COMMENT
// "large" is missing...isn't it?
echo phpUri::parse('https://www.google.com/images/large/')->join('animals/italy/tiger.jpg');
// Adding a slash to the Right
// RESULT
// => https://www.google.com/images/large/animals/italy/tiger.jpg
thanks
No, this is correct behavior.
On Mon, Aug 28, 2017 at 6:09 AM, byman64 [email protected] wrote:
echo phpUri::parse('https://www.google.com/images/large')-> join('animals/italy/tiger.jpg'); echo "\n"; // RESULT // => https://www.google.com/images/animals/italy/tiger.jpg // COMMENT // Is it wrong? "large" is missing...isn't it? echo phpUri::parse('https://www.google.com/images/large/')-> join('animals/italy/tiger.jpg'); echo "\n"; // Adding a slash to Right // RESULT // => https://www.google.com/images/large/animals/italy/tiger.jpg
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/monkeysuffrage/phpuri/issues/14, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1afAHPUEXMmpjPAsxen6dyZdJMfLfPks5scekkgaJpZM4PD73e .
Many thanks for reply and for this fantastic Class ! ciao
[OT] Here but I dont know how add a "Pull Request"
It would be nice a new method on your class: getBaseURL() (Full current URL Path) from $_SERVER I am not a php expert, I am still learning...I found a function and I created a little classe for it. I tried to extend your but as said it was too complex for me.
Here the class
/*
FULL URL
*/
class phpURL { private $s; public $url;
public function __construct( $s )
{
if (empty($s)===true){
$this->s=$_SERVER;
} else {
$this->s=$s;
}
$this->url=$this->getURLFull();
}
public function url_origin( $s, $use_forwarded_host = false ) {
$ssl = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' );
$sp = strtolower( $s['SERVER_PROTOCOL'] );
$protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
$port = $s['SERVER_PORT'];
$port = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port;
$host = ( $use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST'] : ( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null );
$host = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
return $protocol . '://' . $host;
}
public function getURLFull( $s = false, $use_forwarded_host = false ) {
if (empty($s)===false){
$this->s=$s;
} else {
}
$this->url=$this->url_origin( $this->s, $use_forwarded_host ) . $this->s['REQUEST_URI'];
return $this->url;
}
}
// Example 1
echo "Example 1";
$ophpURL1= new phpURL();
echo "
";
echo $ophpURL1->getURLFull();
echo "
";
echo $ophpURL1->url;
ciao
I ran into this one as well, and it was unexpected to me. Why is this "expected behavior"? I was expecting these 2 (slash at the end, or not) to yield the same result:
echo phpUri::parse('https://www.google.com/images/large')->join('animals/italy/tiger.jpg'); echo phpUri::parse('https://www.google.com/images/large/')->join('animals/italy/tiger.jpg');
Thanks for the library!
No because the base path of https://www.google.com/images/large is https://www.google.com/images/ whereas the base path of https://www.google.com/images/large/ is https://www.google.com/images/large/
Ok thanks for your quick reply. The situation I am in is: the user provides what they think is the base path but they provide it without the end slash (using this example, https://www.google.com/images/large).
What is the best practice to turn it into a base path? Detect "no end slash" and append one, then call parse?
Thanks!
No, there's no way of telling if that url is for a file or directory. A web server would know and redirect accordingly.
On Tue, Oct 16, 2018 at 2:21 PM salamonv [email protected] wrote:
Ok thanks for your quick reply. The situation I am in is: the user provides what they think is the base path but they provide it without the end slash (using this example, https://www.google.com/images/large).
What is the best practice to turn it into a base path? Detect "no end slash" and append one, then call parse?
Thanks!
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/monkeysuffrage/phpuri/issues/14#issuecomment-430115241, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1afCqR866W0KEJsrB_Xte0AU3WF-Nnks5ulXrkgaJpZM4PD73e .