Jump to content


Photo

validating data received via GET


  • Please log in to reply
3 replies to this topic

#1 witt

witt
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 28 May 2006 - 09:01 AM

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.

#2 chai

chai
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 28 May 2006 - 11:58 AM

[!--quoteo(post=377776:date=May 28 2006, 04:01 AM:name=witt)--][div class=\'quotetop\']QUOTE(witt @ May 28 2006, 04:01 AM) View Post[/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



#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 May 2006 - 01:32 PM

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\"]in_array()[/a] is the php function that'll do that for you.
Legend has it that reading the manual never killed anyone.
My site

#4 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 28 May 2006 - 02:44 PM

[!--quoteo(post=377816:date=May 28 2006, 08:32 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 28 2006, 08:32 AM) View Post[/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\"]in_array()[/a] is the php function that'll do that for you.
[/quote]
for page2
<?PHP
$randomnumber=$_GET['number']
if($randomnumber > 99){
do whatever!
}
?>

or you could go

if($randomnumber == 80){
do this
}

"Syntax error" .. WHERE THE **** IS IT?!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users