Page 4 of 5
Re: Enhanced register page.
Posted: Wed Apr 07, 2010 8:53 am
by alexander19
Thx a lot man,that really helped me
Btw can you tell me what msgToUser.php contains?
Re: Enhanced register page.
Posted: Wed Apr 07, 2010 5:06 pm
by Torniquet
it contains the following...
Code: Select all
<html>
<head>
Header info as per normal
</head>
<body>
<?php
echo $msgToUser;
?>
</body>
</html>
It is a generic blank page for announcments and suchlike, rather than building 5-6+ different pages for each indevidual announcment like that it just echos out the variable.
you can also stick in a dynamic title by putting the following in the head tags,
Code: Select all
<title><?php echo $dynamicTitle; ?></title>
and just set the title when you set the $msgToUser variable.
Re: Enhanced register page.
Posted: Fri May 14, 2010 9:54 am
by Jony
Ok, this script looks nice.
However, I have a small problem with it.
I used some of it's functions that were not used by halls in his tutorial, one of which is eregi_replace();.
Code: Select all
$emailChecker = eregi_replace("`", "", $emailChecker);
The lines containing this function give an error/warning in which it tells me that the function eregi_replace() is deprecated. Thus, I think that this script cannot be used with this function since php 5.3.0.
How you used it, it is supposed to delete the character "`" from the inputs, right? Since eregi_replace is deprecated, do you know other built in function that acts the same or are we supposed to do it the old fashioned way, by building a function to work with these strings?
I'm just asking this, because I'm new to php and I'm not familiar with all the functions... Sorry if this is a stupid question.
I googled and found this function:
Code: Select all
mixed str_ireplace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
I will be using this instead of eregi_replace. Let me know if i'm doing wrong.
Re: Enhanced register page.
Posted: Fri May 14, 2010 5:57 pm
by Jackolantern
POSIX regular expression extension has been deprecated in favor of the PCRE regular expression extension. See
this page for a list of the differences in methods between these two sets, and it includes links to the PHP Manual pages describing the new methods' usage.
Re: Enhanced register page.
Posted: Sat May 15, 2010 10:15 am
by Torniquet
eregi_replace has now been faded out. jack seems to know more about it than me :p i just know its no longer used lol.
the replacement functions would be preg_replace, or str_replace.
Re: Enhanced register page.
Posted: Wed May 19, 2010 7:51 am
by Jackolantern
Regular expressions can be slow, and POSIX had much slowed performance than the new extension. I also believe there may have been some issues with using POSIX in modern OO structures.
Re: Enhanced register page.
Posted: Tue Nov 02, 2010 4:05 pm
by Infinity
Nice tut, I have a little question, we have created with it a folder to our user, to upload thinks like his avatar.
How would be a code to upload a pic to our server in our folder?
Re: Enhanced register page.
Posted: Tue Nov 02, 2010 5:42 pm
by Jackolantern
Here is a tutorial that shows you how to do it. Probably best to just use an existing script rather than reinventing the wheel. Upload scripts are very common online

Re: Enhanced register page.
Posted: Tue Nov 02, 2010 7:12 pm
by Infinity
Thanks!
I have tried with this and i get everytime this message:
Copy unsuccessfull!
I noticed too that' with the code of tourniquete, it doesn't create the proper folder to the user.
Do you think i'm using a bad free server that don't allow me create folders and/or pictures?
Here is my code:
Code: Select all
<?php
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","100");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="members".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>File Uploaded Successfully! Try again!</h1>";
}
?>
<!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image"></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
</table>
</form>
P.D: Anyone recommends me any free server where i could use MySQL and if it's posible crons?
Re: Enhanced register page.
Posted: Wed Nov 03, 2010 3:07 am
by Jackolantern
I have honestly not gone through that tutorial myself(I have not had the need to upload images thus far). Just Google "PHP upload images" and you will find hundreds of tutorials and scripts. Really, I would just try to download a few different scripts and try them out. You don't need to know how they work, since the scripts are already made and working. In fact, working through a tutorial just increases the chances of making errors while re-creating the code. Just download a script, look through it to make sure there is nothing malicious in it, and then upload it to your server to a test page to try it out.