Jump to content

kenshintomoe225

Members
  • Posts

    36
  • Joined

  • Last visited

Everything posted by kenshintomoe225

  1. I had never used a framework before, but needed to for work. I researched CakePHP, Zend, and Codeigniter. After just trying to get CakePHP and Zend setup for a while, I quickly became frustrated with them. I shouldn't have to learn new coding conventions, nor spend hours configruing front controllers, directories, and .htaccess files just to even use the framework. Then I tried the gem that is Codeigniter. I literally had some code up and running within 10 minutes, and to me, thats what using a framework is all about. Codeigniter ftw!
  2. since you're using CI, just make a view with the header info in it. say our view is 'excelview' class Excel extends Controller { function __construct() { Parent::Controller(); } function export() { $this->load->view('excelview'); } } Inside that view needs to go only the code to generate the excel file, nothing else. On your page make this link: <a href="excel/export">Generate excel file</a> If you've set it up correctly, you will be prompted with a download window and you can then download your file. This isn't the only way to do it, but its the easiest I know of.
  3. within the realm of OOP, there is such a thing as private or public variable scope (and protected in some cases too) Private means the variable is only available to functions in the exact same class as the private variable. Setting a variable to public makes it available to functions inside the class, as well as other areas of your application that might call on it. For example, if I have a class Foo with private variable $bar $foo = new Foo(); echo $foo.bar; //this is invalid if done by an object that is not of type Foo However, if we set the variable $bar to public in class Foo, we can then access in the fashion outlined above. This is generally not good practice though, to make variables in a class available to all classes, but is ok in some situations. You should use getter and setter methods. For example, lets go back to our class Foo. The new class should look like this: class Foo{ private $bar; function __contruct() { $bar = 0; } function getBar() { return $bar; } function setBar($newBar) { $this->bar = $newBar; } }//end class hope this helps
  4. can you post a screen or something of the error you are seeing?
  5. I clicked on the link and got a blank page. What is the current code you are using?
  6. What do the error logs of your webserver say? Look for the most recent entry.
  7. I'm not exactly sure of the behavior of POST between pages, but the $_POST global is populated by the POST field in the HTTP request header. So if it gets overwritten each time, so don't those fields you are setting your session variables to when you link back. I would set your session variables after you have done the authentication and it is valid. Then I would set the session variables to the post variables ONLY once, and that is after authentication. Then we you check them again, check against the session variables instead of the post ones. Is that making sense? I'm a little tired right now hehe. Let's see about a code example: <?php $link = mysql_connect('host','root','pass') or die("you fail"); mysql_select_db("dbname"); session_start(); $username = $_POST['username']; $password = $_POST['password']; if($_SESSION['username']=="" || $_SESSION['password']=="") { die("Please do not leave the username / password field blank!"); } $result = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'"); $number = mysql_num_rows($result); if($number==0) { die("Your login details are not right. Please click the back button and correct them."); } else { $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['password']; } ?> This is roughly what i'm talking about. Also, you are running the authorization script each time you load the page, creating unpredictable results (well, without me stepping through your code for a little while). Use another session variable to signify a user that has already logged in, and don't bother with the authorization if they are already a valid user.
  8. just to kind of add on to what DarkWater is saying, $_GET will be used when the method attribute on a form is set to get. For example: <form name="myGreatForm" action="do/thing" method="GET"> All data is then pass to your PHP script via the URL itself. More specifically, method=get makes use of a specific feature of the HTTP request structure. The other option is POST, where data is not passed via the URL, but in a "part" of the HTTP request that is usually not visible to the user. Since you said you're new, welcome to PHP I'm sure you'll love it as much as we do!
  9. if a variable is set to null, that is not the same thing (to my knowledge of php, and most OO languages) as null. "" represents an empty string, not null. When you query the DB for data, if there is no data, usually it'll return NULL, not the empty string. So if($row['other']) != "") will evaluate to true if nothing is returned, since NULL is returned. Use if(!isset($row['other'])) in your if statement to see if a value was returned or not. This will evaluate to true if $row['other'] is in fact not set, or NULL.
  10. setcookie("step1"); This sets "step1" to "", so even though its an empty string, its still set. To delete your cookie try setcookie("step1", "", time() - 3600); To force it to expire. Also, if your page is redirecting to the index.php page: setcookie("step1", "bboardx", time()+3600); is sitting right there at the top, setting "step1" again. Is this what you intended, or am I reading this wrong?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.