2

I'm trying to write a bit of php code to determine if the user is on the checkout page by getting the current url, and the checkout page url, and comparing the two. The comparison is not working though, and I can't understand why.

This php code here:

$courl = Mage::getURL('onestepcheckout');
$cururl = Mage::helper('core/url')->getCurrentUrl(); 
var_dump($courl);
echo "<br>";
var_dump($cururl);
echo "<br>";
echo "\"$courl\"<br>";
echo "\"$cururl\"<br>";

produces this result:

string(58) "http://127.0.0.1/store/index.php/onestepcheckout/"
string(49) "http://127.0.0.1/store/index.php/onestepcheckout/"
"http://127.0.0.1/store/index.php/onestepcheckout/"
"http://127.0.0.1/store/index.php/onestepcheckout/"

I've tried comparing with ==, ===, and strcmp and none work. I assume this must have something to do with the length discrepancy...

This seems like it must some strange little php nuance I'm not familiar with... I suspected whitespace and tried to trim() both but that didn't have any effect either.

Thanks for any nudges in the right direction! :)

1 Answer 1

1

You can use the parse_url() method.

print_r(parse_url('http://127.0.0.1/store/index.php/onestepcheckout/'));

Array
(
    [scheme] => http
    [host] => 127.0.0.1
    [path] => /store/index.php/onestepcheckout/
)

Then you could use something as simple as

$cururl = Mage::helper('core/url')->getCurrentUrl();     
$url = parse_url($cururl);
if($url['path'] == "/store/index.php/onestepcheckout/"):
// do your magic
endif;
1
  • Thanks! That will work for what I'm trying to do! I'm still a bit curious what's going on with these strings though. Commented Feb 6, 2016 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.