Jump to content

How to get a parameter in the PHP URL (e.g: http://yoursite.com/index.php?page=contact)


stefan1294

Recommended Posts

My question is in the title. How will I be able to get something like that? I did some research, I was checking a couple of tutorials, etc.. But no result, so I'd like to ask it here. Edit: Of course my idea is just to update a 'div' when they go to the about page, for example.

Edited by stefan1294
Link to comment
Share on other sites

hi in getting the url link you need to use this

<?php function curPageURL() {  $pageURL = 'http';   if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}   $pageURL .= "://";   if ($_SERVER["SERVER_PORT"] != "80") {	$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];}  else {	$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];  }   return $pageURL;} echo curPageURL();?>  

try it works for me or use GET method http://www.w3schools.com/php/php_get.asp

Edited by JohnTipperton
Link to comment
Share on other sites

<?phpif ($_GET['page'] != "") {if ($_GET['page'] == "home") {$page_div = $homepage;}  else if ($_GET['page'] == "login") {$page_div = $login_page;}else if ($_GET['page'] == "signup") {$page_div = $signup_page;} else if (($_GET['page'] == "account") && ($login_count == 1)) {$page_div = $account_page;}else{$page_div = $homepage;}}else{  $page_div = $homepage;}?> <?php echo $page_div ?>

Edited by westman
Link to comment
Share on other sites

<?php$page = 'home';  //some default value if(!empty($_GET['page']){  $page = $_GET['page'];} //or, possible one line solution$page = !empty($_GET['page']) ? $_GET['page'] : 'home' ?>

Edited by thescientist
Link to comment
Share on other sites

<?phpif ($_GET['page'] != "") {if ($_GET['page'] == "home") {$page_div = $homepage;}  else if ($_GET['page'] == "login") {$page_div = $login_page;}else if ($_GET['page'] == "signup") {$page_div = $signup_page;} else if (($_GET['page'] == "account") && ($login_count == 1)) {$page_div = $account_page;}else{$page_div = $homepage;}}else{  $page_div = $homepage;}?> <?php echo $page_div ?>

i can't see where those variable com from.$homepage,$login_page,$signup_pag,$account_page may need define.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...