0

Quick PHP Question. I am kinda newb to PHP so bear with me.

Why this ends up with 500 server error?

<?php
//session start
session_start();

//one time ticket is issued
$ticket = md5(uniqid(mt_rand),TRUE);

//put var ticket in SESSION array which is used in next page.
$_SESSION['ticket'][] = $ticket;

...

$_SESSION['ticketPOST'] = $_POST['ticket'];

...

//functionize htmlspecialchars
function h($string) {
    return htmlspecialchars($string, ENT_QUOTES);
}

?>

in same file down below, I wrote something like this:

<form action="brahbrah.php" method="post">
<input type="hidden" name="ticket" value="<?php echo h($ticket); ?>">
<input type="submit" name="indexForm" value="preview">
</form>

any help appreciated. Thanx.

3
  • please tell is it 500 error or some PHP error ? your code seems to generate php error ? Commented Sep 21, 2012 at 7:18
  • I guess both. Strange thing that when I change $_SESSION['ticket'][] = $ticket; to $_SESSION['ticket'] = $ticket; (omit square bracket), this works fine. So this means PHP code error, right? Commented Sep 21, 2012 at 22:56
  • I modified my code example and made it more detailed. Commented Sep 21, 2012 at 23:04

3 Answers 3

7
$ticket = md5(uniqid(mt_rand()),TRUE);

mt_rand is a function and you forgot to put ()

Sign up to request clarification or add additional context in comments.

3 Comments

The type of error depends on his error settings in his php.ini file. I believe that he will get a 500 Internal Server error if he does not have his display_errors set to On.
I tried $ticket = md5(uniqid(mt_rand()),TRUE); and $ticket = md5(uniqid(mt_rand(),TRUE)); both did not work. Does this have to do with my PHP.ini's settig? I will try correcting it too.
Wait I modified it like this and worked fine somehow. $ticket = md5(uniqid(mt_rand(),TRUE));
1

See this link :http://php.net/manual/en/function.mt-rand.php

Try this code:

<?php
//session start
session_start();

//one time ticket is issued
$ticket = md5(uniqid(mt_rand()),TRUE);

//put var ticket to SESSION array which is used in next page.
$_SESSION['ticket'][] = $ticket;

...
?>

mt_rand required ()

1 Comment

Thanx Mariya. I forgot to put it.
0

Set
error_reporting(E_ALL);
ini_set('display_errors', true);

And see what an error

1 Comment

Thanks for the advice. I use BLUEHOST as my test server. I configured php.ini which is located in public_html/ like 'error_reporting = E_ALL' but I still get 500 internal server error...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.