antonysimpson Posted August 17, 2006 Share Posted August 17, 2006 Hiya Guys!!I've got a few links on a page like this: <a href="photo-browse.php?other"> Now I want to know how to check what the "other" value is in the address bar in photo-browse.php?Can anyone help?Antony. Link to comment Share on other sites More sharing options...
Cronthenoob Posted August 17, 2006 Share Posted August 17, 2006 not exactly sure what you want. Buit i think echo $_REQUEST['other']; should print out the value of other. Link to comment Share on other sites More sharing options...
SFB Posted August 17, 2006 Share Posted August 17, 2006 not exactly sure what you want. Buit i thinkecho $_REQUEST['other']; should print out the value of other. in order to print out the value of other shouldnt the url be <a href="photo-browse.php?other=somevalue">my link</a> you can also use get echo $_GET['other']; Link to comment Share on other sites More sharing options...
aspnetguy Posted August 17, 2006 Share Posted August 17, 2006 other is the name of the variable but you did not assign a value to it.If you set your link like this. <a href="photo-browser.php?other=somevalue">Click Me</a> On photo-browse.php you would get the value like this. $valueOfOther = $_GET['other']; $valueOfOther would equal "somevalue" Link to comment Share on other sites More sharing options...
Cronthenoob Posted August 17, 2006 Share Posted August 17, 2006 Is there a difference between $_GET and $_REQUEST ??I was always told to use $_REQUEST because the server I learned on wouldnt accept anything else.I've never seen $_GET before Probably something else my teacher decided to leave out to make me the worst programmer ever. Link to comment Share on other sites More sharing options...
SFB Posted August 17, 2006 Share Posted August 17, 2006 Is there a difference between $_GET and $_REQUEST ??I was always told to use $_REQUEST because the server I learned on wouldnt accept anything else.I've never seen $_GET before Probably something else my teacher decided to leave out to make me the worst programmer ever.i think there are suttle differences between them. its like include and require, they do the same thing. its the end result that everyone is looking for. as long as you can get the same result nobody is going to care. there is also $_post but i dont know if you can use that here. that one is used in processing forms. <forum action="myscript.php" method="post"><input type='text' name='name' />... then you use $name = $_post['name']; to get what the user placed in the name input field Link to comment Share on other sites More sharing options...
aspnetguy Posted August 17, 2006 Share Posted August 17, 2006 There is $_REQUEST, $_GET, and $_POST$_GET is for getting querystrings from a url and $_POST gets data sent by forms using the post method.Now $_REQUEST checks both so if you had a querystring call x (?x=something) and also a form field submitted called x then $_REQUEST would take the $GET value (i think).but if you used GET and POST you could get both values.$x1 = $_GET['x'];$x2 = $_POST['x'];In some situations using REQUEST can allow attackers to inject attacks through the querystring because REQUEST takes GET first even though you intended it to take POST. All they would have ot do is name a querystirng the same as your form field and could override for intended coding.In some cases this could be very dangerous. I never use request I always use the GET or POST for the exact functionality I want Link to comment Share on other sites More sharing options...
Cronthenoob Posted August 17, 2006 Share Posted August 17, 2006 So basically:If i'm using post method in the form, use $_POSTand if I'm using get method in the form, use $_GET ??because $_REQUEST cause allow attackers to inject through the querystring. Link to comment Share on other sites More sharing options...
aspnetguy Posted August 17, 2006 Share Posted August 17, 2006 basically. If you were on a control panel of some sort and values got passed through form post (hidden value that you normally couldn't access) but they used $_REQUEST to get them. If you were to make a querystring with the same name as the hidden field you could set any value you wanted because REQUEST would use the GET value first.Mind you this is not always a threat only in certain situations and the way you write your code has an effect too, but I have just always avoided using REQUEST so I do not have to worry. Link to comment Share on other sites More sharing options...
skym Posted August 17, 2006 Share Posted August 17, 2006 REQUEST also includes COOKIES, not only GET and POST. Link to comment Share on other sites More sharing options...
aspnetguy Posted August 17, 2006 Share Posted August 17, 2006 well I didn't know that...one more reason to not use it, IMO, your giving the attcker some room to work. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 17, 2006 Share Posted August 17, 2006 REQUEST also includes COOKIES, not only GET and POST.Bah, he beat me. skym knows his stuff.There is a config option in php.ini that defines the order in which the three are checked. Collectively, get, post, and cookie are referred to as gpc. The option sets the gpc order in which to check. By default, cookies override post, and post overrides get. But it is always good practice to use the specific one you are looking for, it makes the code a little more understandable as well.Also, there is a use for having a get variable with no value, like this:page.php?submitif (isset($_GET['submit']))It will be set to an empty string, but it doesn't matter if all you want to know is whether or not it exists. Link to comment Share on other sites More sharing options...
aspnetguy Posted August 17, 2006 Share Posted August 17, 2006 Also, there is a use for having a get variable with no value, like this:page.php?submitif (isset($_GET['submit']))It will be set to an empty string, but it doesn't matter if all you want to know is whether or not it exists.Thanks I never thought of that Link to comment Share on other sites More sharing options...
antonysimpson Posted August 17, 2006 Author Share Posted August 17, 2006 HiyaThanks for the replys. Im trying to create normal links on my-photos.php, like <a href="photo-browse.php?album=other>Other Photos</a> And then in photo-browse.php I have the code: <?php$valueOfalbum = $_GET['album'];echo $valueOfalbum>? It comes up with an error, whats wrong guys?I eventually want to put an if code together to check the value and then to echo the appropriate photo. With next and previous photos to load them.Antony. Link to comment Share on other sites More sharing options...
aspnetguy Posted August 17, 2006 Share Posted August 17, 2006 you are missing a ( on the last line Link to comment Share on other sites More sharing options...
antonysimpson Posted August 17, 2006 Author Share Posted August 17, 2006 Added: <?php$valueOfalbum = $_GET['album'];echo $valueOfalbum;>? But still getting error.Thanks,Antony. Link to comment Share on other sites More sharing options...
ThePsion5 Posted August 17, 2006 Share Posted August 17, 2006 What does said error say? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 17, 2006 Share Posted August 17, 2006 >?Something about that I would imagine. Change that to ?> Link to comment Share on other sites More sharing options...
antonysimpson Posted August 18, 2006 Author Share Posted August 18, 2006 Thanks it was the >? works perfectly now!!Antony. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now