forumnz Posted February 16, 2007 Share Posted February 16, 2007 I want to know about the ?a=bc part please. I want to be able to do this with my pages. Any info is greatly appreciated thanks. Sam. Quote Link to comment Share on other sites More sharing options...
btherl Posted February 16, 2007 Share Posted February 16, 2007 In the script index.php, you can use print $_GET['a']; and you will see "bc". That's pretty much it It allows you to set variables for use in php. The same syntax is used by forms with method=get set. The full syntax is ?a=bc&c=de&f=gh That will set $_GET['a'], $_GET['c'] and $_GET['f'] Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted February 16, 2007 Share Posted February 16, 2007 You also could just use this: <?php print "$a"; ?> This would display "bc" in your page; where ever this code was. Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 16, 2007 Author Share Posted February 16, 2007 Ok but what about a website like http://www.oc.school.nz/Main/index.php?mid=-1&rid=orewacollege_pub:1902. It has ?mid=-1&rid=orewacollege_pub:1902 . How did they do that? Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted February 16, 2007 Share Posted February 16, 2007 mid, rid These variables are made up; they are know as "pseudo" variables. You can make up any variable to add to your query string. -1,orewacollege_pub:1902. The letters or numbers after the equals sign is what is being queried or sent to another page, database, etc. The "&" aka "ampersand" lets you add more than one variable to your query string. The "+" aka "plus sign" creates a space in between characters in what ever you define your variable to be. Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 16, 2007 Author Share Posted February 16, 2007 So what would the mid and rid be? Names of database things? Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted February 16, 2007 Share Posted February 16, 2007 They could be names of fields that are in a data table, which are within a database. They also could just be variables that are within a page. Example: Say your domain was "http://www.greatdomain.com". Say you had a page named "page1.php". In "page1.php" you might have a variable know as "$mid". If you type http://www.greatdomain.com/page1.php?mid=Hello When your "page1.php" loads; where ever you had the "$mid" variable; you will now see the word "Hello" This is, if you use this code: <?php print "$mid"; // you can also use "echo" instead of "print"; they have the same effect ?> somewhere within "page1.php" Quote Link to comment Share on other sites More sharing options...
The_Assistant Posted February 16, 2007 Share Posted February 16, 2007 it can be a tad buggy if you just print it straight away. i've noticed older versions of php going a bit crazy over that. use $_GET['variable_name'] if you can. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 16, 2007 Share Posted February 16, 2007 So what would the mid and rid be? Names of database things? they could stand for something. they names dont have to be the same as the names of things in databases. mid may mean member id and rid, well who knows. record id maybe. it can be anything you want, but usually its called something to do with what it will be used for. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 16, 2007 Share Posted February 16, 2007 They could be names of fields that are in a data table, which are within a database. They also could just be variables that are within a page. Example: Say your domain was "http://www.greatdomain.com". Say you had a page named "page1.php". In "page1.php" you might have a variable know as "$mid". If you type http://www.greatdomain.com/page1.php?mid=Hello When your "page1.php" loads; where ever you had the "$mid" variable; you will now see the word "Hello" This is, if you use this code: <?php print "$mid"; // you can also use "echo" instead of "print"; they have the same effect ?> somewhere within "page1.php" You can only use $mid to get the mid variable from the url if register_globals is enabled. If this setting is not enabled then you should use $_GET['mid'] to get the mid variable (?mid=blah) from the url. But you should use $_GET regardless of the register_globals setting. Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted February 17, 2007 Share Posted February 17, 2007 I am running PHP Version 4.3.11 and my register_globals are enabled, yet I still can do this: http://www.greatdomain.com/page1.php?mid=Hello and have this code in my page <?php print "$mid"; // you can also use "echo" instead of "print"; they have the same effect ?> and still send the "mid" variable's string to page1.php; where ever my code is placed in it. Using "$_GET" can sometimes pose a problem because of an alert the browser gives you on page with "$_GET" in it; when page is reloaded. The alert basically tells you that the page is sending form values. So that is why I stay away from "$_GET"; except when validating. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 17, 2007 Share Posted February 17, 2007 Well... you shouldn't use the browsers back button when you have submitted data to a site. You should provide a link/button to go back. Or tell the browser to not cache the data that is submitted to and from the site using headers. Having register_globals on can create security exploits within your code allowing an attacker to take control of your site. This is the main reason why register_globals is now disabled by default as of PHP4.3 and will be removed soon be removed when PHP6 launches. Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted February 17, 2007 Share Posted February 17, 2007 You cannot predict what your website viewer will do. They might very well use the brower back button; it is commonly used by a majority of people, even when links are provided. If "$_GET" is suggested; it should be noted that you need to create a header to prevent page cache. Otherwise the alert will prompt; which sometimes can confuse or distress end user. Having register_globals on can create security exploits within your code allowing an attacker to take control of your site. This is the main reason why register_globals is now disabled by default as of PHP4.3 and will be removed soon be removed when PHP6 launches. When that day comes; then I may start using "$_GET"; until then, it works fine for me and most other people. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 What the hell are you talking about? "Using "$_GET" can sometimes pose a problem because of an alert the browser gives you on page with "$_GET" in it; when page is reloaded." I have never ever ever seen a browser alert when a page has a query string. Register globals is a security hazard, that is why it was removed. If you're having weird alerts because you're trying to use valid code, there's another problem - the rest of your code, likely. Using undeclared variables is poor practice, not using $_GET, $_POST, etc is even poorer. Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted February 17, 2007 Share Posted February 17, 2007 Form submission alert can happen when page uses $_GET too transfer data from one page to another and the back button is used. I have never ever ever seen a browser alert when a page has a query string. You may need to test your pages a little better then; because I have. I have never had any security problems with "register_globals" on; others might. PS: Nice of you to reply to this post; although you would not reply to my message. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 Please show me an example of a page that does this. PS: What message? If you are one of the many people to PM me asking me to help with your post, you might want to go read the forum rules where it says NOT to do that. That's why I didn't respond to your message. So, nice of you to read the rules before whinging. Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted February 17, 2007 Share Posted February 17, 2007 I do not have an example to show, because I do not use the "$_GET" method in my coding practices, but I have seen this occur in testing. No ones whining - just stating the facts - a piece of coding you said would work on your sever did not work on mine. So something was not right with your code, so I sent you a message. The only reason I PM you was because you would not reply to post; must have knew it was wrong and didn't want to admit it. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 I've never gotten a PM from you - what are you talking about? The only PMs I have are from yesterday from someone else. Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted February 17, 2007 Share Posted February 17, 2007 It's alright; don't worry about it. I sent it to you maybe 2 or 3 days ago. Not that big of a deal. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 17, 2007 Share Posted February 17, 2007 To phpBeginner06, please read http://shiflett.org/articles/how-to-avoid-page-has-expired-warnings about how to avoid getting those warnings. Ken Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 17, 2007 Share Posted February 17, 2007 I recently used something like this while creating a link to a php file that made a new web page based on info from the db. Basically mid and rid are items found in the database. On the page the link takes you too, you would use $_GET to redefine the variable in the new page. This allows you to do a query using whatever the variable was. It basically allows you to carry over a variable into a new page. Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted February 17, 2007 Share Posted February 17, 2007 This is what I use to do this. Say the user clicks on a link that's index.php?id=2 <?php echo "<a href='test.php'>Main</a> <a href='test.php?id=2'>Other Page</a>"; $id = $_GET['id']; //If the id is blank or it's just index.php... if($id == "") { echo "<p align='center'>Welcome to the index page.</p>"; } //If the id is equal to "2"... if($id == "2") { echo "<p align='center'>Welcome to the other page</p>"; } ?> Hope this helps. Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted February 17, 2007 Share Posted February 17, 2007 kenrbnsn that would work or you could use a header to prevent cache also. Greaser9780 and Unholy Prayer that would work also. But all I am saying is that, if you just want to transfer a string to another page; you can just use: <?php print "$mid"; ?> if there are only a few things that $mid should be able to print and not allow anything else; you could just use this above the code (i use this to validate - this is where I use $_GET): <?php // This script will redirect viewer to home page; if they type in wrong query string. @$mid = stripslashes($_GET['mid']); if ( strcasecmp($mid,"something") != 0 ) { header("Location: http://www.greatdomain.com"); exit; } ?> You may not want to use this if the $mid variable string could be more then a few different things. But for only a few things that a string could be/equal; this works great. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.