Php Questions?! - From: alex1985

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #19) by alex1985 on Mar 10 2008, 05:36 PM. (Line Breaks Removed)
So, is it better to create login system with AJAX support? If yes, please indicate the tutorial.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Php Questions?! - From: alex1985

alex1985
Listen, as I'm novice in PHP, I will ask certain questions in this topic hoping on your contribution.

CODE
$dbhost='.....';


CODE
<?php
//The Database Information//
$dbhost='localhost';
$dbname='alex1985_test';
$dbusername='alex1985_admin';
$dbuserpass='0505009127';
//Creating Connection To The Database//
mysql_connect ($dbhost, $dbusername, $dbuserpass);
//Select The Certain Database//
mysql_select_db ($dbname) or die ('Can Not Select Database');


CODE
<?php
//Start The Session//
//Always Must Be On Top//
session_start();
//Include Configuration File//
include('config.php');
?>


There are questions which I derived practicing the coding:

1. Do you put spaces between words and brackets, as well as comas when you do coding. For instance, $dbhost, $dbusername. Is it right, or you do not have to use space between.

2. On some tutorials, the users have been used the character ', some of the are using ". What is the different between them. Can I use ' or ". or it does not matter everything.

There are many aspects that I wanna ask you about.

Could check the coding format, and tell me about the mistakes I did. Please, let me know as soon as possible.

 

 

 


Reply

rvalkass
QUOTE(alex1985 @ Mar 8 2008, 02:33 PM) *
CODE
<?php
//The Database Information//
$dbhost='localhost';
$dbname='alex1985_test';
$dbusername='alex1985_admin';
$dbuserpass='0505009127';
//Creating Connection To The Database//
mysql_connect ($dbhost, $dbusername, $dbuserpass);
//Select The Certain Database//
mysql_select_db ($dbname) or die ('Can Not Select Database');


Just a pointer, you don't need to finish a comment with //. There are two sorts of comments in PHP - single line and multi-line. The single line comment is started with a // and applies from that point until the end of the line. This means you can place it after a line of code, like this:

CODE
$username = 'alex1985'; // This is the username you log in with


A multi-line comment applies over multiple lines, and does require you to finish it. It is started with /* and ends with */
The advantage, of course, is that you can have much longer comments without really long lines:

CODE
/*
  This function does something really cool.
  You can pass it all sorts of variables.
  Actually, it is quite pointless.
*/
function pointless(){
    return true;
}


QUOTE(alex1985 @ Mar 8 2008, 02:33 PM) *
1. Do you put spaces between words and brackets, as well as comas when you do coding. For instance, $dbhost, $dbusername. Is it right, or you do not have to use space between.


It doesn't make any difference, but generally people put spaces in to make their code easier to read. For example, the second example here is much easier to read than the first example:

CODE
$dbh=mysql_connect($host,$username,$password)://Connect
$dbh = mysql_connect($host, $username, $password); // Connect


It is up to you to code how you want, but generally spaces are put after commas (i.e. in a list of parameters or variables) and around binary operators (=, +, -, *).

QUOTE(alex1985 @ Mar 8 2008, 02:33 PM) *
2. On some tutorials, the users have been used the character ', some of the are using ". What is the different between them. Can I use ' or ". or it does not matter everything.


The single quote character takes its contents literally. Nothing placed in single quotes is parsed. This makes it faster, and more secure, but limits the uses.

The double quote character parses its contents. That makes it slower, but a bit more useful.

For example:

CODE
$number = 7;
echo 'The \n number \n was... \n $number';
echo "The \n number \n was... \n $number";


Would output:

QUOTE
From the first echo (single quotes):

The \n number \n was... \n $number

From the second echo (double quotes):

The
number
was...
7

 

 

 


Reply

alex1985
So, spaces are allowed?!

For instance, if(...some function...) and if (...some function...), is it right or wrong?

Can use both of them or not?

Reply

rvalkass
You can use either of them and they will both work perfectly well. It depends entirely on your coding style as to which one you want to use. It is generally advised to add whitespace wherever it will make the code easier to read. So, if you look at a line, and you think it looks a little bit squashed, add some spaces in to make it easier to read.

Tabs are also a good idea to represent subsections of code. For example, in an if statement, the code that is executed is usually tabbed in, to separate it from the 'main' code:

CODE
if ($var == $var2)
{
    echo 'They are the same';
}

else
{
    echo 'They are not the same';
}

Reply

alex1985
OK. When you put equal sign in the coding, do I have to make spaces as well? Or generally both of them will be working?!

Reply

rvalkass
As has been said, you do not need spaces. It will work whether they are there or not. However, they are generally added to make it easier to read.

Reply

alex1985
Thanks for your previous replies, were really helpful! How do I protect my user passwords in my database. If someone hacked the database, it was really hard for him to get passwords from that database. Please, list all good ways to do that.

Reply

jlhaslip
The most common method is to 'encrypt' the user_password before you store it into the file or Database.
Then you need to encrypt the input before you compare the entry to the stored value. If they encrypted input is the same as the encrypted stored value (using the same encryption method, then the user is validated.

*EDIT*
In register.php, this is the insert command I use:
CODE
$query = "INSERT INTO users (
            first_name,
            last_name,
            email,
            password,
            registration_date,
            phone,
            cell,
            level,
            years,
            note)
            
            VALUES (
            
            '$fn',
            '$ln',
            '$e',
            SHA1('$p'),
            NOW(),
            '$p',
            '$c',
            '$dl',
            '$y',
            '$n'
             )";        
            $result = @mysql_query ($query); // Run the query.
            if ($result) { // If it ran OK.

And in the Login.php, here is the code for checking the password you get at log-in with the encryted one in the Database:
CODE
SELECT user_id, first_name, level FROM users WHERE email='$e' AND password=SHA1('$p')


The password is selected based on the encrypted value, so in the Log-in script, handle the results based on the number of records returned. If zero, no member has that email and password. If one, the person should be allowed into the page/site.

Reply

alex1985
Could you write the whole process how you do it from the beggining?!

Reply

jlhaslip
Post the register script you are using and the log-in script, too.
It will be easier to modify your script than explain the whole workings of mine, but basically, after you have the password on the register script, as you insert it into the database, use the SHA1() function to encrypt it.
And when you retrieve the password on log-in, also encrypt it using the SHA1() function before you compare the two.

Attach your scripts and I will Mod them for you as best I can.

*edit*

Oops! I added the method into the posting two up from here.

Reply

Latest Entries

alex1985
So, is it better to create login system with AJAX support? If yes, please indicate the tutorial.

Reply

jlhaslip
AJAX is a scripting language that uses javascript and other stuff to be able to provide your site with automatic and (nearly) instant updates of information.
PHP and ASP are 'Server-side' scripting languages. Javascript is 'Client-side'. In the past, javascript could do things like local error-checking before a page was submitted to the server for refreshing the information. Now, javascript in the Browser can work with php at the Server to send your page information from the server without requiring a page refresh or reload. AJAX is what you use to do this.

Reply

alex1985
I will check them on the server and clerify my questions!!!

What is AJAX?

Reply

sonesay
The only reason people name files differently is preference. The same goes for variable names, You can have $name1 and $name2 and if both hold the same value then there should be no difference. You can choose to name your database file what ever you like for example.. db.php or db_connect.php etc. I think thats what your asking right? I'm sorry your just not being too clear in what exactly your asking.

Reply

alex1985
Take a look of this code at: PHP Tutorials.

Just explain me the info that relates to 2 of my questions...

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Similar Topics

Keywords : php, questions, alex1985

  1. Questions?!
    PHP (4)
  2. Gd Functions
    Questions (2)
    Hi all I want begin a new project , my new project is Photo blog ( weblog and image album ) in one
    script for example you can post many image in one post at once case . so its very good and very easy
    but we have some problems . if you can plz help me to fix this problems for example : we need
    change image size for page speed ( we dont want show 16 image in one page ) * we need GD functions
    to change image size to smaller and then show smaller image at page if you know source or tutorial
    about change image size plz post here . thankx we know we can change image size (w....
  3. Javascript To Php - A Few Questions
    (1)
    I am rewriting a Javascript into PHP, but I have two questions: How can I write these functions in
    PHP? Math.floor Math.ceil I'm sure the answer is obvious, but I really can't find it...
    /laugh.gif' border='0' style='vertical-align:middle' alt='laugh.gif' /> ....
  4. 2 Questions
    (7)
    i have 2 questions about PHP...please don't answer like "use google"...or something...because i
    tried and didn't find anything..so 1. example..i have a varible called $var and it
    contains 50 characters..so how can i write only part of them (1,2,3,20)? 2. example like the one
    before... i have a varible called $var with 50 characters..how can i write the first /second
    /third.. charachter from the $var tnx;)....
  5. Wap Forum
    several questions on WAP forums (9)
    /blink.gif' border='0' style='vertical-align:middle' alt='blink.gif' /> Right i want to set up a
    wap forum for rap battling. I think i need to use php, although i might need wml not sure. so
    questions: 1) WML or PHP? 2) Can i get a forum/message board script? 3) Where can i get it? Thanks
    in advance Not making helpful thread topics and titles results in warnings, or in extreme cases, a
    ban. Don't fall into the crack. ....
  6. A Lot Of Php Questions Part 2
    (8)
    Ok, here's another. After looking at many PHP codes, I will call it "PHP Shortcuts". Do you
    still know any other "PHP Shortcuts"? Example, to "print" the visitor's IP address, I use CODE
    <html><head></head><body><?php print
    $_SERVER['REMOTE_ADDR']; ?></body></html> After seeing
    someone's codes, I saw an easy way CODE
    <?=$_SERVER['REMOTE_ADDR'];?> So, you know any more of that? And for
    MySQL, I know there are many ways to retrieve the results. ....
  7. A Lot Of Php Questions
    please do help me (3)
    First , i'm planning to use preg_match, ereg_match, etc.. I think "preg" and "ereg" uses
    something like in the Apache's RewriteModule the " " something like that... Do you know a
    tutorial that will easily teach me on how to do that? Second , I'm planning to use Apache
    Rewrite. But I really don't know how to use. Do you know a tutorial that will easily teach me on
    how to do that? Third , while openning some php scripts, I didn't get the meaning of example:
    CODE <?php $sample1->//some string here ?> What does it mean? I di....
  8. Html To Php Questions
    (3)
    Hi, I would like to know if it is safe to change HTML files to PHP files by just changing the
    dotHTML extension to dotPHP?? I tried it to a single html file because i used a php code of blog,
    and it worked. I'm using Internet Explore version 6 and it's working fine. I would like to
    know if the PHp files would work for other browsers after changing dotHTML to dotPHP extension.
    Thanks....

    1. Looking for php, questions, alex1985

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for php, questions, alex1985

*MORE FROM TRAP17.COM*
advertisement



Php Questions?! - From: alex1985



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE