Jump to content

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.