xbl1 Posted November 23, 2007 Share Posted November 23, 2007 Hi;I'd like to ask you how i get a varibal value from url.the url is "http://mysite.com/country/Category.php?page=1/"i want to get the page value.i tried the following, it does not work.echo $_GET["page"];echo $_POST["page"];echo $_REQUEST["page"];could anyone tell me hoe to get the value of page, please. Link to comment Share on other sites More sharing options...
Ingolme Posted November 23, 2007 Share Posted November 23, 2007 It's:echo $_GET['page']; but your URL has an unnecessary / at the end. Link to comment Share on other sites More sharing options...
zppblood Posted November 23, 2007 Share Posted November 23, 2007 You can use $_GET['page'] or $_REQUEST['page']. You will not get information from the URL with $_POST['page'], you would need to submit a form. $_REQUEST will get information from $_GET, $_POST, and $_COOKIE. Link to comment Share on other sites More sharing options...
mc_keny Posted November 23, 2007 Share Posted November 23, 2007 Whats the different when you use single quotes instead of double cause i use double and it work fine eg $name = $_GET["name]; Link to comment Share on other sites More sharing options...
Ingolme Posted November 23, 2007 Share Posted November 23, 2007 Single or double quotes don't make any difference. Link to comment Share on other sites More sharing options...
boen_robot Posted November 23, 2007 Share Posted November 23, 2007 Single or double quotes don't make any difference.Not completely right. Double quotes allow you to refer to PHP variables within the strings they encompass, whereas everything in single quotes is outputted literally. The overhead of using double quotes in strings with no variable references is unnoticeably small though (from one test that I made it's under 0.1ms at 1 million iterations), so if you can't make it a habbit to use single quotes - so be it. Link to comment Share on other sites More sharing options...
xbl1 Posted November 23, 2007 Author Share Posted November 23, 2007 Not completely right. Double quotes allow you to refer to PHP variables within the strings they encompass, whereas everything in single quotes is outputted literally. The overhead of using double quotes in strings with no variable references is unnoticeably small though (from one test that I made it's under 0.1ms at 1 million iterations), so if you can't make it a habbit to use single quotes - so be it.my url become to "http://www.mysite.com/country/Category.php?page=1"and i tried to print out the value by print_r[$_REQUEST['page']it still not work.the following is my work, could you help me to find out why? thanks.in the .htaccess file, i create a rewrite rule.RewriteEngine OnRewriteCond %{QUERY_STRING} ^page=([^&]+)RewriteRule ^([a-z]+)/Category.php$ /Category.php?[L]then in the index.php file<a href="country/Category.php?page=1">the country </a> <br><a href="city/Category.php?page=1"> the city </a> <br>and in the category.phpecho $_GET['page'];or $_REQUEST['page'];or $_POST['page'];but it does not work. Link to comment Share on other sites More sharing options...
mc_keny Posted November 23, 2007 Share Posted November 23, 2007 let me see the form, and $_REQUEST is enough. Link to comment Share on other sites More sharing options...
Synook Posted November 24, 2007 Share Posted November 24, 2007 print_r isn't an array, it is a function - try print_r($_REQUEST['page']); I'm not too familiar with mod_rewrite, but that rule might be chopping off the querystring - what do you see in your browsers URL bar when you click on a link to category.php ? Link to comment Share on other sites More sharing options...
xbl1 Posted November 24, 2007 Author Share Posted November 24, 2007 print_r isn't an array, it is a function - tryprint_r($_REQUEST['page']); I'm not too familiar with mod_rewrite, but that rule might be chopping off the querystring - what do you see in your browsers URL bar when you click on a link to category.php ? it shows with the "http://www.mysite.com/country/Category.php?page=1" Link to comment Share on other sites More sharing options...
Synook Posted November 24, 2007 Share Posted November 24, 2007 That is correct - try print_r($_REQUEST); Oh btw - what version of PHP are you using? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.