0

I'm working from a Wordpress website, and I need to be able to create a template for a real quick-and-simple custom order page.

The plan is to create pages so that the URL of said page will be http://www.website.com/order-1234

And then, the template being used for that page will have PHP in it that will try and grab the "1234" portion of the URL, and use it as a variable.

$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$order_id = intval(substr($url, strrpos($url, '/order-') + 4));
echo $order_id;

But the above code is returning a zero "0"

8
  • 1
    Shouldn't that +4 be +6 - i.e strlen('/order-') Commented Jul 3, 2013 at 3:47
  • Try +7 - $order_id = intval(substr($url, strrpos($url, '/order-') + 7)); see phpFiddle - phpfiddle.org/main/code/tse-vbr Commented Jul 3, 2013 at 3:52
  • 1
    actually shouldn't it be +7? Regardless, it should still return "r-1234" -- ahh, the zero is false as it's not a value that can be an int when using "intval()". Try removing that function and see what result you get. Commented Jul 3, 2013 at 3:52
  • even substr($url,-4); but you still need to do some checking Commented Jul 3, 2013 at 3:54
  • @Dagon wouldn't that limit orders to 4 digits, as it would not work for order-123 or order-12345 Commented Jul 3, 2013 at 3:59

1 Answer 1

1

try by using www.website.com/order?id=1234

and use

 $getid = $_GET['id']

also when you want to use the get to show the page use the request function

 if ($_REQUEST['id'] == $getid) {
 // do something here
}

something like that :)

Sign up to request clarification or add additional context in comments.

3 Comments

This works, although some would say that http://www.website.com/order-1234 looks cleaner/nicer than http://www.website.com/order?id=1234
@Sean you probably right but its the easiest and the fastest way to do it as i know about php so far :P
Unfortunately, Wordpress won't allow me to manually append "?id=1234" to the permalink url when creating a new page. It takes out the question mark. I could modify the mod_rewrite rules, but this needs to be as simple and quick as possible.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.