Redirection in PHP after IF / ELSEIF / ELSE statements
Scroll down to later in the topic.
|
I will try to tell the basic things that you will need.
First of all: php.net is great! To identify the user you can start a session with Code:
http://php.net/session_start Code:
http://php.net/session_register To check the user name you can read the database with mysql_* functions, create an include file with your connection informations to make it easy: Code:
http://php.net/mysql_connect Code:
http://php.net/mysql_select_db Code:
http://php.net/mysql_fetch_array Code:
http://php.net/mysql_result Code:
http://php.net/mysql_query Code:
http://php.net/mysql_fetch_array http://php.net/mysql_escape_string http://php.net/mysql_real_escape_string Well, I believe that you have some material to start building your app, go for it... and if you have some doubt just ask! []'s, FMC! |
Thanks FMC for the tips. I had used the steps here (http://www.php-mysql-tutorial.com/us...n/database.php) but they don't seem to be working well.
Regarding the code you gave me, does it all go inside the same PHP file? (Except for the one that is used with php include().) Do I add the usernames & passwords myself? Do I need to include the php.net links, or are they just for refference? And is there any way to keep track of stuff a user has picked up/achieved? For inserting usernames & passwords, can I do that manually in a database? Or is there a SQL script/program/etc. I can use to do it for me? Thanks! |
Well, I just gave you some tips, you will have to use your creativity to put everything together and build your app!
The links to php.net are just for reference, there you can know everything the function does (or do, I don't know, I'm braziliam)! The first important thing to start to code is to be sure what your software will be, you have to imagine how it will work and everything, try to imagine something like: 1 - A form to input log/pass. 2 - If the log/pass is correct, than register the session and redirect the user to the initial page, it it is incorrect show the form again. 3 - Show something to the user and let him decide what to do. 4 ... I don't know exactly what you want to do, even if I knew it would be impossible to me to give you the exact lines that you need, that's why I'm linking everything to you, this way you can study and do it by yourself! You could start by doing something like: connection.inc.php (a include for every single page) login.inc.php (to be sure that the user is logged in, if not, redirect to log page) login.php (form for the user to login and register the session) index.php (page to show something for the user after login) Oh, another function that you will probably like is "header", with this function you can redirect the user to another page: php.net/header (search for "Location"). []'s, FMC! |
Ah, thanks for the clarification.
I should be good to go now, so I guess have to test it out and see what happens now. :) Cheers, Joro. |
Just in case you don't have it, here's the online refs to all the MySQL docs, inc examples, for all version from 3 -> 5; see top left section of page for the link to your version.
http://dev.mysql.com/doc/refman/5.0/en/ |
Thanks chrism, I'll have to check that link out later though, right now I've got an impeding problem.
http://slycorps.6te.net/quest/ If you go there, and type in the word bar, you get a page that tells you "you're in a bar" but if you type in phonebooth, it tells you "you're in a phonebooth" and then gives you the error message right after. Code:
<html> |
As I already told, you can use the header function to redirect the user to another page:
header("Location /yourpage.php"); []'s, FMC! |
EDIT: This is getting crazy. Turns out closing the brackets after each echo, and making repetitive statements "elseif" works.
But how do I do header functions? |
I know I may be smacked in the head for saying this, but Dreamweaver can do all this and more. You can build a comprehensive system from the ground up very quickly and easily, and it will look after SQL and Users etc. for you.
|
Quote:
|
It probably won't. And on top of that, I don't have 400$ (Or whatever amount it is now) to spend on Dreamweaver, I don't think I can run it well, and school's out so I can't use the labs.
I still haven't figured out how to use "header" after an if/elseif/else statement. Any ideas? And can I send a user back to a page + echo something new? |
Also, afaik, Dreamweaver has never been ported to Linux ... unless you're using virtual OS.
Anyway, you won't learn as much that way. |
Plus it doesn't seem to be working under Wine right now, and I doubt CrossOver has a solution...
Man, if only Adobe would bring the creative suite to Linux. I mean, they can keep it closed if they want... But native Photoshop on Linux is a huge boon. [/offtopic] Guys, I could use a bit of help here! I can't make that bloody "header" function do anything when it's in an IF statement! Any fixes? :( |
Do you receive any warn message when you execute your if statement?
The header function will not work if there is some output to browser before it is called. A simple \n is sufficient to make header not work at all! Try this code and take it as a example: Code:
<?php |
All times are GMT -5. The time now is 03:59 PM. |