We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,344 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Show page with random number in session

Dear friends,

I have this form (raffle_winner_form.htm) with the action in raffle_winner.php:

<form name="form1" method="post" action="raffle_winner.php">
<label>
Max numbers: <input type="text" name="max">
</label>

<p>
<label>
<input type="submit" name="submit" value="calculate">


</label>
</form>

raffle_winner.php

<?php
session_start();
$session = session_id();
$number = mt_rand(1,$_POST[max]);
?>

My intention is to show the random number in a page that it is storing the session id with the generated number in an array and show it like:

www.example.com/raffle_winner.php?session_id=r4r4r4r44 for example.

Any ideas?

Thank you in advance.
Cole

2
Contributors
1
Reply
1 Hour
Discussion Span
1 Year Ago
Last Updated
2
Views
coleguitajuan
Newbie Poster
21 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Try this code:

function getRandomString($length=5) 
{
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $string = '';   
    for($i = 0; $i < $length; $i++) 
    {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}
$number = getRandomString($_POST[max]);
vibhaJ
Posting Shark
958 posts since Apr 2010
Reputation Points: 161
Solved Threads: 190
Skill Endorsements: 3

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0593 seconds using 2.72MB