Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > rocksolid.shared.helpdesk > #37 > unrolled thread
| Started by | Anonymous@novabbs.i2p (Anonymous) |
|---|---|
| First post | 2020-12-20 00:43 +0000 |
| Last post | 2020-12-20 23:19 +0000 |
| Articles | 6 — 5 participants |
Back to article view | Back to rocksolid.shared.helpdesk
Notice: Undefined variable: Anonymous@novabbs.i2p (Anonymous) - 2020-12-20 00:43 +0000
Could it be a typo ? trw <trw@anon.com> - 2020-12-20 01:12 +0000
Re: Notice: Undefined variable: Retro Guy <retro_guy@retrobbs.rocksolidbbs.com> - 2020-12-20 03:21 -0700
Re: Notice: Undefined variable: retro.guy@rocksolidbbs.com (Retro Guy) - 2020-12-20 10:38 +0000
Re: Notice: Undefined variable: Anonymous <poster@anon.com> - 2020-12-20 05:07 -0800
Re: Notice: Undefined variable: Anonymous@novabbs.i2p (Anonymous) - 2020-12-20 23:19 +0000
| From | Anonymous@novabbs.i2p (Anonymous) |
|---|---|
| Date | 2020-12-20 00:43 +0000 |
| Subject | Notice: Undefined variable: |
| Message-ID | <00178a157a08fbb015413efe9715b88b$1@news.novabbs.com> |
Hello. I'm in a need of a bit of help. I'm trying to make a website in php. However, in order for users to access a page in this website, they'll need to have an account. This account requires a captcha. However, whenever I try to get an account, my error logs say that a variable is undefined. Here's part of my code:
index.php:
<!doctype html>
<html>
<head>
<style>
*{margin:{number}px; padding:{number}px;}
#account{border-radius: {number}px {number}px {number}px {number}px; border: {number}px solid {color}; width:
{number}px; margin-top: {number}px; margin-left: {number}px; }
#login{border-radius: {number}px {number}px {number}px {number}px; border: {number}px solid {color}; width: {number}px; margin-top: {number}px; margin-left: {number}px; margin-right: {number}px; }
</style>
</head>
<body style="background-color:{color}">
#####<?PHp
require_once("connect.php") ;
if(isset($_POST['register'])){
$user_name = $_POST['user_name'] ;
$password = $_POST['password'] ;
if($user_name != "" and $password != "" and $_POST['code'] === $_SESSION['captcha_code'])
$q= "INSERT INTO `user` (`id`, `user_name`, `password`)
VALUES(' ' , ' ".$user_name." ' , ' ".$password." ')
" ;
if(mysqli_query($con, $q)){
echo '{text1}' ;
}else{
echo "(text2)" ;
}
}
?>#####
<h1><strong>{Some Text}<strong></h1>
<div id="registration">
<h2>{Some Text}</h2>
<form method="post">
Intended username:<br>
<input type="text" name="user_name" /><br>
Intended password:<br>
<input type="text" name="password" /><br>
#####<img src="cap.php"><br/><label for="code">captcha:</label><input type="text" name="code" />#####
<input type="submit" name="register" value="Submission" />
</form>
</div>
</body>
</html>
cap.php:
<?php
session_start( ) ;
#####$captcha = ' ' ;
for($x = 0 ; $x< 7 ; $x++){
$captcha .=chr(rand(97, 122)) ;
}
$_SESSION['captcha_code'] = $captcha ;#####
$font = '/fonts/ttf/28dayslater.ttf' ;
$image = imagecreatetruecolor(170, 60) ;
${variable1} = imagecolorallocate($image, {number}, {number}, {number}) ;
${variable2} = imagecolorallocate($image, {number}, {number}, {number}) ;
${variable3} = imagecolorallocate($image, {number}, {number}, {number}) ;
imagefilledrectangle($image, 0, 0, 200, 100, ${variable3}) ;
#####imagettftext($image, 30, 5, 10, 40, ${variable}, $font, $_SESSION['captcha_code']) ;#####
header("Content-type: image/png") ;
imagepng($image) ;
?>
Error Log Output:
#####Notice: Undefined variable: _SESSION in {directory}/index.php on line {number}#####
For what connect.php is and what the INSERT INTO values are as mentioned above in index.php, they're databases that are used in order for users to register, and I also believe that they're unimportant in terms of my issue. The different {number}, {color}, {text}, {directory}, and {variable} brackets are supposed to represent different elements in my code that I believe aren't necessary to type out and are also elements that I feel somewhat insecure sharing. Of course, if there's any information that I can provide you or anything that you're confused about, then please feel free to ask. Since the code may be a bit long to some, I put hashtags around sections of code that I think are especially important to read. Anyway, I believe that with the code that I wrote out, the SESSION variable shouldn't be undefined, as it was defined in cap.php (captcha). However, here I am, not knowing why I keep on getting this error and {text2}. If you have any idea why I may be getting this error, if you see a mistake in the code, and/or if you know any links and websites that might help, please reply. I would love some advice, as I don't know what's wrong at all. Thanks.
--
Posted on novaBBS
news.novabbs.com
[toc] | [next] | [standalone]
| From | trw <trw@anon.com> |
|---|---|
| Date | 2020-12-20 01:12 +0000 |
| Subject | Could it be a typo ? |
| Message-ID | <b57b69c78175acb392f5039503868450@def4> |
| In reply to | #37 |
>session_start( ) ; When I do copy and paste, there is a whitespace between the brackets, where it should say: session_start(); cheers trw -- Posted on def4
[toc] | [prev] | [next] | [standalone]
| From | Retro Guy <retro_guy@retrobbs.rocksolidbbs.com> |
|---|---|
| Date | 2020-12-20 03:21 -0700 |
| Message-ID | <20201220032137.1412dd1a@desktop14.dt> |
| In reply to | #37 |
On Sun, 20 Dec 2020 00:43:32 +0000 Anonymous@novabbs.i2p (Anonymous) wrote: > Hello. I'm in a need of a bit of help. I'm trying to make a website > in php. However, in order for users to access a page in this website, > they'll need to have an account. This account requires a captcha. > However, whenever I try to get an account, my error logs say that a > variable is undefined. Here's part of my code: Usually the log would tell you which variable is undefined. Then you know which variable you need to trace back to see when it should get defined. Does the log provide this info?
[toc] | [prev] | [next] | [standalone]
| From | retro.guy@rocksolidbbs.com (Retro Guy) |
|---|---|
| Date | 2020-12-20 10:38 +0000 |
| Message-ID | <65f85e14e588904d442f0de127cbe004$1@news.novabbs.org> |
| In reply to | #42 |
Retro Guy wrote: > Usually the log would tell you which variable is undefined. Then you > know which variable you need to trace back to see when it should get > defined. Does the log provide this info? I somehow missed the bottom of your post where you say it's _SESSION that's undefined. Do you have session_start() also in index.php? Without it you won't have $_SESSION variables available. -- Posted on Rocksolid Light news.novabbs.org
[toc] | [prev] | [next] | [standalone]
| From | Anonymous <poster@anon.com> |
|---|---|
| Date | 2020-12-20 05:07 -0800 |
| Message-ID | <he.660.48msjb@anon.com> |
| In reply to | #37 |
>>50d90268088e7734ea >Do you have session_start() also in index.php? Without it you won't have $_SESSION variables available. Are you sure ? I thought $_SESSION is a superglobal. -- Posted on def2
[toc] | [prev] | [next] | [standalone]
| From | Anonymous@novabbs.i2p (Anonymous) |
|---|---|
| Date | 2020-12-20 23:19 +0000 |
| Message-ID | <2e7dc8318d17415313085feea1e3ae0b$1@www.novabbs.com> |
| In reply to | #44 |
Anonymous wrote: >>>50d90268088e7734ea >>Do you have session_start() also in index.php? Without it you won't have $_SESSION variables available. > Are you sure ? I thought $_SESSION is a superglobal. It is as long as you session_start() https://errorsea.com/what-is-the-php-session-and-how-to-use-_session/ -- Posted on novaBBS www.novabbs.com
[toc] | [prev] | [standalone]
Back to top | Article view | rocksolid.shared.helpdesk
csiph-web