Jump to content

validating data received via GET


witt

Recommended Posts

I basically have a random number created that's sent via GET to another page. So basically page.php is sending rand(00,99) to page2.php and a link such as page2.php?rand=53 is given. On page2.php, the number 53 would have a certain meaning. Now what I want is so that if someone types in page2.php?rand=80, they are redirect to page.php instead of showing page2.php with nothing on it. I don't want to use a database by the way.
Link to comment
https://forums.phpfreaks.com/topic/10635-validating-data-received-via-get/
Share on other sites

[!--quoteo(post=377776:date=May 28 2006, 04:01 AM:name=witt)--][div class=\'quotetop\']QUOTE(witt @ May 28 2006, 04:01 AM) [snapback]377776[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I basically have a random number created that's sent via GET to another page. So basically page.php is sending rand(00,99) to page2.php and a link such as page2.php?rand=53 is given. On page2.php, the number 53 would have a certain meaning. Now what I want is so that if someone types in page2.php?rand=80, they are redirect to page.php instead of showing page2.php with nothing on it. I don't want to use a database by the way.
[/quote]

If the purpose you want to do this checking is for security, you might want to create a session of user that is logged in your page.

Assign a session id to user when they are logged in. And on every page, check whether session id is empty.
If so, just redirect them to page.php.

If you just want to make sure the databse have records with the eg.rand=53, on page2.php,simply write a sql to check on the db.
If it return a value, proceed wit hyour proces, else redirect user to page.php

I'm confused by your request. You want to choose a random number between 0 and 100 and some of those random numbers will be 'acceptable' to page2.php and others are unacceptable and cause a re-direction to page.php

Is that what you want? If so, retrieve the value of $rand from the $_GET array and check the passed value of $rand against an array of 'acceptable' numbers in page2.php. [a href=\"http://ca.php.net/manual/en/function.in-array.php\" target=\"_blank\"][b]in_array()[/b][/a] is the php function that'll do that for you.
[!--quoteo(post=377816:date=May 28 2006, 08:32 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 28 2006, 08:32 AM) [snapback]377816[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'm confused by your request. You want to choose a random number between 0 and 100 and some of those random numbers will be 'acceptable' to page2.php and others are unacceptable and cause a re-direction to page.php

Is that what you want? If so, retrieve the value of $rand from the $_GET array and check the passed value of $rand against an array of 'acceptable' numbers in page2.php. [a href=\"http://ca.php.net/manual/en/function.in-array.php\" target=\"_blank\"][b]in_array()[/b][/a] is the php function that'll do that for you.
[/quote]
for page2
[code]<?PHP
$randomnumber=$_GET['number']
if($randomnumber > 99){
do whatever!
}
?>[/code]

or you could go

[code]if($randomnumber == 80){
do this
}[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.