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(); 
echo "<br>";
echo "<br>";
echo "\"$courl\"<br>";
echo "\"$cururl\"<br>";

produces this result:

string(58) ""
string(49) ""

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! :)


You can use the parse_url() method.


    [scheme] => http
    [host] =>
    [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
  • 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. – user1390471 Feb 6 '16 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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