/    Sign up×
Community /Pin to ProfileBookmark

edit a file for me

hey everybody,
I need your help coz welsh made me a script for a register script but the captcha part didn’t work. could you please take it out for me?

register.php

[code=php]<?php
session_start();

if(isset($_SESSION[‘message’])){
echo “<hr>” . $_SESSION[‘message’] . “<hr>”;
unset($_SESSION[‘message’]);
}
?>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>

<body>
<form action=”register.action.php” method=”post”>
<table border=”0″ cellspacing=”2″ cellpadding=”2″>
<tr>
<td>Username:</td>
<td><input type=”text” name=”username”></td>
</tr>
<tr>
<td>Password:</td>
<td><input type=”text” name=”password”></td>
</tr>
<tr>
<td><img src=”CaptchaSecurityImages.php?width=100&height=40&characters=5″ alt=”captcha” /></td>
<td><input id=”security_code” name=”security_code” type=”text” /></td>
</tr>
<tr>
<td colspan=”2″ align=”center”><input name=”Submit” type=”submit” value=”Register”></td>
</tr>
</table>
</form>
</body>
</html>
[/code]

register.action.php

[code=php]<?php
session_start();

if(($_SESSION[‘security_code’] == $_POST[‘security_code’]) && (!empty($_SESSION[‘security_code’])) ) {
if(isset($_POST[‘Submit’])){

$username = $_POST[‘username’];
$password = $_POST[‘password’];
$error = 0;

$file = fopen(“slogin_users.txt”, ‘r’);

while(!feof($file)){
$row = explode(” “, fgets($file));
if($username == $row[0]){
$error = 1;
}
}

fclose($file);

if($error == 1){
$_SESSION[‘message’] = “Username <b>” . $username . “</b> is already taken, please enter a different Username.”;
header(‘Location: register.php’);
} else {
$file = fopen(“slogin_users.txt”, ‘a+’);

$newData = “n” . $username . ” ” . $password;
fwrite($file, $newData);

fclose($file);

$_SESSION[‘message’] = “Username <b>” . $username . “</b> registered.”;

unset($_SESSION[‘security_code’]);

header(‘Location: register.php’);
}
}
} else {
$_SESSION[‘message’] = “CAPTCHA verification failed, please try again.”;
header(‘Location: register.php’);
}
?>[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Fire_CatauthorSep 11.2009 — I am asking you because i am really bad at php and don't know what to edit in the files.

Thanks

Fre Cat
Copy linkTweet thisAlerts:
@welshSep 11.2009 — if you want the captcha out then if i remember right this should be it:
[code=php]
<?php
session_start();

if(isset($_SESSION['message'])){
echo "<hr>" . $_SESSION['message'] . "<hr>";
unset($_SESSION['message']);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="register.action.php" method="post">
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="text" name="password"></td>
</tr>

<tr>
<td colspan="2" align="center"><input name="Submit" type="submit" value="Register"></td>
</tr>
</table>
</form>
</body>
</html>
[/code]


[code=php]<?php
session_start();
if(isset($_POST['Submit'])){

$username = $_POST['username'];
$password = $_POST['password'];
$error = 0;

$file = fopen("slogin_users.txt", 'r');

while(!feof($file)){
$row = explode(" ", fgets($file));
if($username == $row[0]){
$error = 1;
}
}

fclose($file);

if($error == 1){
$_SESSION['message'] = "Username <b>" . $username . "</b> is already taken, please enter a different Username.";
header('Location: register.php');
} else {
$file = fopen("slogin_users.txt", 'a+');

$newData = "n" . $username . " " . $password;
fwrite($file, $newData);

fclose($file);

$_SESSION['message'] = "Username <b>" . $username . "</b> registered.";

unset($_SESSION['security_code']);

header('Location: register.php');
}
}
?>[/code]
Copy linkTweet thisAlerts:
@Fire_CatauthorSep 11.2009 — ok great

thanks!

Edit: Though, there is one problem: when I type: username: testuser and password: testpass it outputs like this in the txt file:

testuserntestpass

instead of

testuser[COLOR="Red"],[/COLOR] testpass

And the username availability doesn't work either

Thanks
×

Success!

Help @Fire_Cat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...