Marius B Posted July 1, 2009 Share Posted July 1, 2009 Hello. As you see, I'm new here. I started to look at websites and thought like: "Woah. Now I really want to learn PHP and CSS" So I got some friends of me to help me get started. But there is something I really want to know. I don't get how people make the http://www.domain.com/index.php?action=blabla As you see I made the ?action=blablabla bold. That's what I'm wondering about. Some help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/ Share on other sites More sharing options...
Bendude14 Posted July 1, 2009 Share Posted July 1, 2009 When sending data using the GET method it is displayed in the URL as a key value format. In your example action is the key and blabla been the value a more clearer example would be ?user=ben&age=20 See these links .... http://www.w3schools.com/PHP/php_get.asp http://www.tizag.com/phpT/postget.php Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867168 Share on other sites More sharing options...
Marius B Posted July 1, 2009 Author Share Posted July 1, 2009 Would it be possible to load another page with the GET method? Example: I'm on my index.php, and I'm pressing a button which will lead you to contact.php. Instead of going to contact.php, would it be possible to like load the content from contact.php with this? index.php?page=contact Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867171 Share on other sites More sharing options...
Bendude14 Posted July 1, 2009 Share Posted July 1, 2009 yes of course you could check at the top of your page similar to this... <?php if($_GET['page'] == 'contact') { include("contact.php"); } else { //otherwise load default page include("default.php"); } Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867184 Share on other sites More sharing options...
Marius B Posted July 1, 2009 Author Share Posted July 1, 2009 Thank you so much for your help! 2 Thumbs up. Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867186 Share on other sites More sharing options...
syed Posted July 1, 2009 Share Posted July 1, 2009 Marius B There are different application states, GET is one of them. Using GET allows you to submit data to a webserver for processing or simply maintain data from one page to another. However, there are limitations, that is using GET, you can only send a certain amount of data. I don't know the exact number about 300 something characters in the url. Also your data is clearly visible, so you would not send password using GET. Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867202 Share on other sites More sharing options...
Marius B Posted July 1, 2009 Author Share Posted July 1, 2009 I tried to add the code Bendude14 posted. But my page keeps refreshing and then apache doesn't respond. I know why it does, because it will check every time the site refresh. Where should I add this code? I added this right under <body> <?php if($_GET['page'] == 'home') { include("index.php"); } else if($_GET['page'] == 'band') { include("band.php"); } else if($_GET['page'] == 'media') { include("media.php"); } else if($_GET['page'] == 'tour') { include("tour.php"); } else if($_GET['page'] == 'releases') { include("releases.php"); } else if($_GET['page'] == 'contact') { include("contact.php"); } else { include("index.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867226 Share on other sites More sharing options...
bmw2213 Posted July 1, 2009 Share Posted July 1, 2009 I tried to add the code Bendude14 posted. But my page keeps refreshing and then apache doesn't respond. I know why it does, because it will check every time the site refresh. Where should I add this code? I added this right under <body> <?php if($_GET['page'] == 'home') { include("index.php"); } else if($_GET['page'] == 'band') { include("band.php"); } else if($_GET['page'] == 'media') { include("media.php"); } else if($_GET['page'] == 'tour') { include("tour.php"); } else if($_GET['page'] == 'releases') { include("releases.php"); } else if($_GET['page'] == 'contact') { include("contact.php"); } else { include("index.php"); } ?> Add the code where you want to include those pages. I.e if you were going to make a menu that would be the same on every page, you would want to put that block under the code for the menu You could also look at a switch statement instead of using all those else..if (just my personal preference) Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867235 Share on other sites More sharing options...
Marius B Posted July 1, 2009 Author Share Posted July 1, 2009 Sorry, but I didn't understand what you were pointing to. This is my code so far. I bet all of you can see my problem now: <html> <link rel="stylesheet" type="text/css" href="./style.css" /> <head> <title> Marius' Page </title> </head> <?PHP $toswitch = $_GET['page']; switch($toswitch){ case 'home': include("index.php"); break; case 'band': include("band.php"); break; case 'media': include("media.php"); break; case 'tour': include("tour.php"); break; case 'releases': include("releases.php"); break; case 'contact': include("contact.php"); break; default: include("index.php"); break; } ?> <body> <div id="top"></div> <div id="banner"> <img src="banner.png" alt="Banner"/> </div> <div id="bunn"></div> <div id="top"></div> <div id="menu"> <p> <a href="index.php?page=home">Home</a> | <a href="index.php?page=band">Band</a> | <a href="index.php?page=media">Media</a> | <a href="index.php?page=tour">Tour</a> | <a href="index.php?page=releases">Releases</a> | <a href="index.php?page=contact">Contact</a> </p> </div> <div id="bunn"></div> <div id="top"></div> <div id="main"> <div id="tekst"> Text </div> </div> <div id="bunn"></div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867246 Share on other sites More sharing options...
Eggzorcist Posted July 1, 2009 Share Posted July 1, 2009 It's commonly used with database. Say you have multiple pages of information, all somewhat the same format. for example a member profile page. blabla.php?user=fred then you can make a sql query using $_GET['user'] (which would = fred) and get all the information on fred providing how you set the variables on the page. Although beware, as any user can manipulate the URL, there are security issues which should be looked up and taken care of in order to well secure your url and sql queries... Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867249 Share on other sites More sharing options...
bmw2213 Posted July 1, 2009 Share Posted July 1, 2009 Sorry, but I didn't understand what you were pointing to. This is my code so far. I bet all of you can see my problem now: <html> <link rel="stylesheet" type="text/css" href="./style.css" /> <head> <title> Marius' Page </title> </head> <?PHP $toswitch = $_GET['page']; switch($toswitch){ case 'home': include("index.php"); break; case 'band': include("band.php"); break; case 'media': include("media.php"); break; case 'tour': include("tour.php"); break; case 'releases': include("releases.php"); break; case 'contact': include("contact.php"); break; default: include("index.php"); break; } ?> <body> <div id="top"></div> <div id="banner"> <img src="banner.png" alt="Banner"/> </div> <div id="bunn"></div> <div id="top"></div> <div id="menu"> <p> <a href="index.php?page=home">Home</a> | <a href="index.php?page=band">Band</a> | <a href="index.php?page=media">Media</a> | <a href="index.php?page=tour">Tour</a> | <a href="index.php?page=releases">Releases</a> | <a href="index.php?page=contact">Contact</a> </p> </div> <div id="bunn"></div> <div id="top"></div> <div id="main"> <div id="tekst"> Text </div> </div> <div id="bunn"></div> </body> </html> What you have now is a code that will include the information before the page. The easiest way would be to put the switch statement where you want the included page to go. In your code, I would imagine the information should go into the main section or like this: <html> <link rel="stylesheet" type="text/css" href="./style.css" /> <head> <title> Marius' Page </title> </head> <body> <div id="top"></div> <div id="banner"> <img src="banner.png" alt="Banner"/> </div> <div id="bunn"></div> <div id="top"></div> <div id="menu"> <p> <a href="index.php?page=home">Home</a> | <a href="index.php?page=band">Band</a> | <a href="index.php?page=media">Media</a> | <a href="index.php?page=tour">Tour</a> | <a href="index.php?page=releases">Releases</a> | <a href="index.php?page=contact">Contact</a> </p> </div> <div id="bunn"></div> <div id="top"></div> <div id="main"> <?PHP $toswitch = $_GET['page']; switch($toswitch){ case 'home': include("index.php"); break; case 'band': include("band.php"); break; case 'media': include("media.php"); break; case 'tour': include("tour.php"); break; case 'releases': include("releases.php"); break; case 'contact': include("contact.php"); break; default: include("index.php"); break; } ?> <div id="tekst"> Text </div> </div> <div id="bunn"></div> </body> </html> But I really don't know what those sections are for, so put it where you want, but as soon as that php code runs, it gets put into page. Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867257 Share on other sites More sharing options...
Marius B Posted July 1, 2009 Author Share Posted July 1, 2009 It's commonly used with database. Say you have multiple pages of information, all somewhat the same format. for example a member profile page. blabla.php?user=fred then you can make a sql query using $_GET['user'] (which would = fred) and get all the information on fred providing how you set the variables on the page. Although beware, as any user can manipulate the URL, there are security issues which should be looked up and taken care of in order to well secure your url and sql queries... Ah, I see. Thanks for the information. And thanks to bmw2213, syed and bendude14 for additional information. * Marked as solved * Link to comment https://forums.phpfreaks.com/topic/164397-solved-making-a-site-with-action/#findComment-867264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.