Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

mpeg4v3 posted:

Stuff

No.

That is way overly complex for just starting it out, and overly complex for about any framework I would ever use or try to code. It looks like a tangled mess, and I think you are going to go suicidal.

The idea of MVC is separation. Your model should run on its own. You should be able to take the model out and replace it with a completely different model type written by someone else, and not have to change your view or controller framework code. Same thing for the other parts. There will probably be some interdependencies, but still, you should strive for separation.

If you take a look at the zend framework, you can run Zend_View all by itself without the controller. If you really wanted to you could setup a codeignitor site and use the code ignitor controller, Zend_View and your own model. That is how it should work.

If I were you I would code a controller. Then after that is all sweet, code a view thingy. Then try and tackle this model/module/plugin thing after the fact. I see your plugins as being something where part of your model would have a plugin manager or something, then your controller would run it and pass the output onto the view. Something really simple like this maybe?

php:
<?
class MyPage extends Controller
{
   function index()
   {
      $pluginManager = new MyPluginManagerThing($this->db);
      $pluginManager->loadPlugins();
      $output = $pluginManager->run($this->GetArgs);

      $view = new MyView('mytemplate.php');
      $view->set('pluginOutput', $output);
      $view->render();
   }
}
?>
I am not saying it has to be like that, but thats just an idea. Notice that the view and controller frameworks have no direct knowledge of your plugin manager. Within a controller method your run your plugin thing passing it data from the controller (get arguments) and a db connection, then you create a view and pass it data returned from the model to display.

Your plugins might each have their own view and their own php template files. That would work too, but I would jump off of that bridge later. I think the plugin manager will end up being its own layer with one or more layers underneath it, but it my example above all that logic is separate and encapsulated.

I guess my advice is to not think about how all of this is going to work together, but rather how you are going to write the pieces of your project so each one runs fine by itself.

Adbot
ADBOT LOVES YOU

Yeehaw McKickass
Dec 15, 2004

DarkLotus posted:

What do you mean "Confirms the mail was sent"? Just making sure the mail sending function completed without errors?

I mean within the form box, without having to refresh the page.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

Yeehaw McKickass posted:

I mean within the form box, without having to refresh the page.

This isn't difficult, you'll have an HTML form, then you'll use jQuery to validate the input and submit via AJAX to form.php. If successful, the jQuery can hide the form and display a success notification without reloading the page.

The example below does ZERO input validation. You will at bare minimum want to validate user input via jQuery and then again via PHP.

formtest.html
code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $('#formResults').hide();
    $('#testButton').click(function () {
      var formData = $('#testForm').serialize();
      $.ajax({
        type: "POST",
        url: "process-form.php",
        data: formData,
        success: function(html){
          $('#inputForm').hide();
          $('#formResults').html(html).show();
        }
      });
      return false;
    });
  });
</script>
</head>
</head>
<body>
<div id="inputForm">
  <form name="test" id="testForm">
  Field: <input type="test" name="field" /> <br />
  <input type="button" name="submit" id="testButton" value="Submit" />
  </form>
</div>
<div id="formResults"> </div>
</body>
</html>
process-form.php
php:
<?php
  if (!empty($_POST['field'])) {
    echo "Form Submitted!";
    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
  }
  exit;
?>

If you want some help, hit me up on AIM darklotus781. I'll be hit or miss today but will be available later tonight.

DarkLotus fucked around with this message at 21:01 on Mar 19, 2010

mpeg4v3
Apr 8, 2004
that lurker in the corner

Begby posted:

more :words:

Doh :( Thanks again for the advice and suggestions. I think the whole integrating a global plugin system is the only real thing I'm having problems with at this point, and every solution I try just keeps making it super complicated. I'll go back to the drawing board and try and conceptualize your suggestions into something more simple.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

mpeg4v3 posted:

Doh :( Thanks again for the advice and suggestions. I think the whole integrating a global plugin system is the only real thing I'm having problems with at this point, and every solution I try just keeps making it super complicated. I'll go back to the drawing board and try and conceptualize your suggestions into something more simple.

Don't get down.. this is not easy stuff, and it takes practice to think in a different way about these types of problems.

Here's some crappy pseudo-code:

php:
<?
class Blerf {
  public function drawView()   {
    echo "<p>Blerf!</p>";
  }
}

class Bloof {
  public function drawView()   {
    echo "<p>Bloof...</p>";
  }
}

class CalendarModel {
  public function getData()   {
    return array(
      3 => array( new Blerf() ),
      5 => array( new Bloof() , new Blerf() )
    );
  }
}

class CalendarController extends MasterController {
  
  function index()   {
    $model = new CalendarModel();  
    $data = $model->getData();
    $view = new CalendarView( $data );
    $view->render();
  }
}

class CalendarView {
  private $data;
  function __construct( $data )   {
    $this->data = $data;
  }

  public function render()   {
    for( $i = 1; $i <= 5; $i++ )
    {
      echo "<div style='float:left;wdith:50px;'><p>$i</p>";
      if( isset( $this->data[$i] )  {
        foreach( $this->data[$i] as $thing ):
          echo $thing->drawView();
        endforeach;
      }
      echo "</div>";
    }
  }
}
?>
This CalendarController will draw our awesome 5-day month calendar, and on days 3 and 5, it will display events.

Now notice a couple things:

1: The calendar, which is displaying stuff, has absolutely no idea what it's displaying. It has no clue what a Blerf or a Bloof is, nor should it care. All it "requires" is that *something* have a getData() method be assigned as it's $model, and the data it' gets from this method be an array, and the things inside each array be an array of objects that have a drawView() method. Your customer doesn't want the Bloof module any more? No big deal, your model stops returning those objects and your calendar doesn't care. Oh no! Now you need to display Gleeps and Glops! Better change that calendar code.... oh wait, we don't need to, as long as the Gleep and Glop class have drawView() methods.

2. If we need to draw a calendar view in a different class / module, as long as we pass it data in the same format, we can use the same view class:

php:
<?
class SuperPage {
  function index()  {
    $calModel = new CalendarModel();
    $pieModel = new PieModel();
    $calView = new CalendarView( $calModel->getData();
    $pieView = new PieView( $pieModel->bakePies() );

    $calView->render();
    $pieView->render();
  }
}
?>
The pieces parts, by not needing to know about much of anything else can be used anywhere, and as long as you conform to some rules (i.e. "If something is going to get displayed in a calendar, it *has* to have a drawView() method" ) you can eliminate dependencies; CalendarView doesn't give a rats rear end if the data it was passed came from CalendarModel or HotPantsSaleDaysModel, as long as the data is structured the way it expects it will happily do it's thing.

EDIT: Sorry I didn't touch on the plugin architecture part of you question, but I already posted a lot of :words: and it's Friday night... feel free to AIM me during the week ( I don't sign on on weekends ) if you want to ask questions.

Lumpy fucked around with this message at 01:53 on Mar 20, 2010

McGlockenshire
Dec 16, 2005

GOLLOCKS!

isagoon posted:

On the whole templates topic...

I rewrote some of my block processing code, and I have this. IS there any way to catching parse errors in the included code? I think I have seen Magento do it.

Parse errors are an uncatchable fatal.

If you're letting users edit templates via your UI, you can probably just shell out to php -l -- that's a lowercase L. This'd be impractical (slow) to do every time you include the template.

mpeg4v3
Apr 8, 2004
that lurker in the corner

Lumpy posted:

more helpful :words:

EDIT: Sorry I didn't touch on the plugin architecture part of you question, but I already posted a lot of :words: and it's Friday night... feel free to AIM me during the week ( I don't sign on on weekends ) if you want to ask questions.

I know I keep saying it, but thanks again. I think I've begun to understand how to structure everything now. I also spent a fair bit of time last night reading through the Kohana 101 guide, which, even though I've never used Kohana before, was very helpful conceptually with understanding everything.

In fact, considering time issues, I think I am just going to say screw it and use Kohana as a framework for this entire project, as I'm realizing I've got even less time than I thought to try and get this into a workable state. I also think I'm just going to say screw it to the plugin system- it's making things too complex. I can make due with manually referencing new features instead of trying to come up with some sort of hooks system that'll only load certain data for certain portions on certain pages. I'm still trying to decide between Kohana 2 and 3. I know 2 has much more documentation so far, but I've been seeing people say that 3 is supposed to be much better from a coding and efficiency standpoint, and if I'm going to jump into this, I might as well learn on the newer version, even if it means more research in the beginning.

epswing
Nov 4, 2003

Soiled Meat
Attaboy. Kohana also lets you write shareable modules (plugins) to extend the functionality of the framework.

As for 2 vs 3, they're soon going to release 2.4 soon which fixes and improves upon many 2.3 issues. Also, 2.x is not end-of-life, work on 2.x will continue after 3 is released. From what I've read about 3, the whole routing system is different, but we have yet to see how it really stacks against 2.

Just remember that there are probably many more sites built with 2.x than with the as-yet-unreleased 3.0, so it'll be easier to find help/documentation for 2.x

epswing fucked around with this message at 00:37 on Mar 21, 2010

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

epswing posted:

Attaboy. Kohana also lets you write shareable modules (plugins) to extend the functionality of the framework.

As for 2 vs 3, they're soon going to release 2.4 soon which fixes and improves upon many 2.3 issues. Also, 2.x is not end-of-life, work on 2.x will continue after 3 is released. From what I've read about 3, the whole routing system is different, but we have yet to see how it really stacks against 2.

Just remember that there are probably many more sites built with 2.x than with the as-yet-unreleased 3.0, so it'll be easier to find help/documentation for 2.x

Seconding this recommendation for Kohana 2.X

The docs for 2 are not exactly awesome, and for 3.... :eng99:

cka
May 3, 2004
Thirding the Kohana 2 recommend. I'm working on something right now in v3, and my main source of documentation and reference is Google/kerkness.ca wiki/kohana forum posts. Kohana 2 will definitely do what you need it to, and there's enough docs to help you get to the finish.

And for the record, the routing engine in 3 really is completely different than in 2, but also seems more powerful (mostly because you can do neat poo poo like on-the-fly scaffolding triggers in modules/subdirectory controller requests to hide their true paths and such.)

gwar3k1
Jan 10, 2005

Someday soon
I hate only getting dev time on a weekend for this, but such is my arrangement.

Anyway, I have a situation where I need users to be able to download files from a restricted directory without the outside world having access.

I can put a .htaccess file in the file directory to prevent directory listing but I can't CHMOD the access rights as I need the ability to download the file, not just read it for page output. Aturaten was helpful getting me to this point of knowledge.

I'm storing the file path and names in a database, so it's dead simple to hide that filepath from the user which will hopeuflly cut down on people accessing files from directories they shouldn't have access to.

I can get a file to download using headers which is great but I can't do a redirect back to the page they were on. They will therefore be stuck on a blank page which is no good. Can someone point me in the right direction with this code?

php:
<?
  function downloadfile($sPage, $sPath, $sFile)
  {
    if(!file_exists($sPath."/".$sFile))
    {
      $bReturn = false;
    }
    else
    {
      header('Content-disposition: attachment; filename='.$sFile);
          header('Content-type: application/octet-stream');
          readfile($sPath."/".$sFile);
      header('Location: '.$sPage);
      $bReturn = true;
    }
    
    return $bReturn;
  }
?>

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Probably shouldn't be doing a Location header after sending a file attachment header.

waffle iron
Jan 16, 2004
A location header after sending a file is out of specification.

For the issue of sending the file, I would recommend using X-Sendfile instead of using PHP to read it out. On large files PHP could hit the memory limits and die in the middle execution.

http://codeutopia.net/blog/2009/03/06/sending-files-better-apache-mod_xsendfile-and-php/

gwar3k1
Jan 10, 2005

Someday soon
Thanks both of you.

I contacted my host and shared hosting doesn't allow installation of custom modules. Its a bit annoying as I'm having to develop on my shared hosting account but I will likely have more freedom when the site is moved to company hosting and then the xsend would probably be ideal.

Is it bad form to use target='_blank' just to do what I need? It annoys me having blank tabs for downloads in Firefox so I've disabled that as a matter of installation.

Edit: I should also say I don't want to use javascript for this. Its a self imposed restriction which may hinder me slightly but still, I told the client no javascript.

Edit 2: Brilliant! The target _blank method doesn't need any cleanup: by the look of it, the tab/window will automatically close when the user interacts with the download.

gwar3k1 fucked around with this message at 17:24 on Mar 21, 2010

mpeg4v3
Apr 8, 2004
that lurker in the corner
Okay, I've been messing around with Kohana all day, and I really think I finally understand how everything works. I do have one quick question though, relating to view layouts.

Let's say I'm going to have three Controllers and their respective Views/Models: Calendar, Shifts, and Events. Shifts will be specifically related to retrieving and displaying Shift Scheduling information ("John Doe works 3/22 from 12pm-4pm as a Desk Assistant at the Main Desk"). Events will deal with retrieving any special events ("There is a potluck on 3/23 from 12pm-1pm in the Lunch Room"). I want to have views using this data:
1.) A basic Calendar view showing no data, just the days of the selected week.
2.) A "shifts during the week" view using the Shift data overlaid on top of the basic Calendar.
3.) An "events during the week" view using the Event data overlaid on top of the basic Calendar.

Now, since both #2 and #3 are going to use a lot of the same Views as the basic Calendar, I was wondering what the generally recommended method of organizing the files and layouts for all three were. So far I can only think of the following two ways:
1.) In the Calendar view, have one central php file that renders the entire thing, and have an $additional_content variable in the location where any additional content is meant to be displayed. The basic Calendar controller will render it with the $additional_content variable empty, while the Shifts or Events controller will set $additional_content equal to a new Shifts or Events view.
2.) Split the Calendar view into several views, such as the Calendar header view, the Calendar footer view, the Calendar hourly times (12am-12am) list view, the Calendar content view, etc., each with their own php file. The basic Calendar controller would create new Views for each of the above, and render them in the correct order. The Shifts Controller would do the same, except it would also insert its own respective views at certain points (the same with Events). So after the Calendar content view, would come the Shifts view, followed by the Calendar footer view, for example.

#1 seems more efficient and less file-heavy/complex, but #2 seems more flexible and future proof, and I'm wondering which option is generally the preferred option, or if there's other options I haven't thought of (which is the more likely idea).

mpeg4v3 fucked around with this message at 05:36 on Mar 22, 2010

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

mpeg4v3 posted:

Calendar stuff

I am assuming you want something like my gmail calendar. I can display just the days, or select one or more calendars to display on the single calendar. For instance I can select my work calendar, my personal calendar, the office calendar, and the calendar for the conference room. All the events show up together on the same displayed calendar but color coded (for instance the conference room events all show up pink, my personal calendar is blue etc.).

If that is something that you are going for, then this might make sense.

A. Have a single view, this view takes draws the calendar layout, then within that layout displays the individual events.

B. Have a calendar events object, which is basically a glorified array that you can pass events to (the events would come from your models), then you pass this object to your view. Something like this

code:
$cal = new Calendar();

// Add some stuff
$cal->AddEvent('My EventName', '03/22/2010 1:00pm', '3/22/2010 2:30pm', 'Blue');
$cal->AddEvent('Proctologist Appointment', '03/24/2010 8:00am', '03/24/2010 9:00am', 'Green')

// Get our models
$shifts = new Shifts($mydb);
$events = new SpecialEvents($mydb);

$myShifts = $shifts->fetch($fromDate, $toDate);

foreach ($myShifts as $shift)
{
  $cal->AddEvent($shift->name, $shift->start, $shift->end, $color);
}

//etc

// Render the view
$view = $this->LoadView(calendarView.php);
$view->Set('cal', $cal);
I am not sure how kohana does views, but that should give you an idea. Also, the event dates should probably be datetimes and not spelled out.


Something like this would allow you to create as many calendar modules as you wanted and render them all in the same calendar view (like gmail).

Also, now that your view is only working with a single class, it becomes pretty easy to create multiple views. You could have a week view, a daily view, a monthly view, etc.

Thirteenth Step
Mar 3, 2004

Im 'fairly' new to PHP, and it's my first time posting in here so please go easy...!

I'm trying to create a login/timetable system as a sort of learning project for myself for a very small company I used to work for, aswell as probably proposing this to them in the future if it ever gets finished., they're quite easy like that.

I'm trying to create a login script whereby if an admin enters their details it will direct them to ADMIN.PHP if a user enters their details it will send them to USER.php I have a 'usertype' field in my mysql table which either contains 'user' or 'admin' and this is how the difference between admins and users is defined.

My poo poo pseudocode is;

code:
enter login details 
 check username
 check password
 check 'usertype' field in DB for correct username and password entered
  if 'user' 
   send to (users.php) 
  if 'admin' 
   send to (admin.php)
  else
   send to (rejection.php)
and the actual code I have right now is;

code:
<?php
session_start();

mysql_connect('localhost', 'root', '');
mysql_select_db('richard');

function clean($value) {
        if(get_magic_quotes_gpc()) $value = stripslashes($value);
        return trim(mysql_real_escape_string($value));
}

if($_POST['login'] && $_POST['username'] && $_POST['password']) {
                $username = clean($_POST['username']);
                $password = md5($_POST['password']);

                $admincheck = mysql_query("SELECT usertype FROM staff WHERE username = '$username' AND password= '$password'");
                if(mysql_num_rows($admincheck) == 1) {
								$_SESSION['username'] = $username;
                header("Location: admin.php"); 
                                exit;
                }

                $usercheck = mysql_query("SELECT usertype FROM staff WHERE username = '$username' AND password = '$password'");
                if(mysql_num_rows($usercheck) == 'user') {
                                $_SESSION['username'] = $username;
                header("Location: users.php");
                                exit;
                } else 
				{
                                header("Location: FAIL.php");
                }
}

?>
I know it's a mess :ohdear:

What that code is doing right now is directing ALL login attempts to USERS.PHP rather than the admins -> admins.php, users -> users.php and incorrect usernames/passwords -> fail.php

Thanks for any help

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thirteenth Step posted:

Im 'fairly' new to PHP, and it's my first time posting in here so please go easy...!


What that code is doing right now is directing ALL login attempts to USERS.PHP rather than the admins -> admins.php, users -> users.php and incorrect usernames/passwords -> fail.php

Thanks for any help

code:
if(mysql_num_rows($usercheck) == 'user') {
You are comparing the number of rows returned to a string. If there are any rows returned, this comparison will evaluate to 'true' and will always send everyone to USERS.php

You want to check the *value* of the returned row.

php:
<?
if(mysql_num_rows($usercheck) === 1) 
{
 // we got exactly one result back, this is good
 
 // get the row into an array
 $myUser = mysql_fetch_assoc( $usercheck );
 
 // based on value, do stuff.
 switch( $myUser['usertype'] )
 {
   case 'user':
    // do user stuff
   break;
   case 'admin':
    // do admin stuff
   break;
   default:
    // they have a user type I don't handle
 }

}else
{
 // we got no user, or more than one user, which is bad
}
?>
Do yourself and the server you run on a HUGE favor, and use prepared statements / PDO for your MySQL stuff. Removes most glaring security holes for you by sanitizing data and so on.

mpeg4v3
Apr 8, 2004
that lurker in the corner
Okay, I lied about giving up on the whole Plugin system idea. My mind kept drifting back to it, and this is what I figured out for it. I'm going to use the main index page as an example. It uses the Main_Controller, has no models of its own and just one basic view, but has several different plugins that want to display data in it (the Shifts plugin wants to display any upcoming shifts for the current week for a user in a list, the Notifications plugin wants to display any important notifications for the user to see, stuff of that nature). This is all using Kohana phrasing and layout. More crappy pseudo code! Yay!

  1. The Website_Controller class creates a new Plugin_Model.
  2. The Main_Controller class (extending Website_Controller) calls Plugin_Model->getPlugins('main').
  3. Plugin_Model->getPlugins('main') selects the data from the DB. The select would be something like: "SELECT model, section, rank FROM plugins WHERE page = 'main' ORDER BY section, rank". In this example, it would return something like this:
    code:
    Model			Section			Rank
    notifications		mainIndexView		1
    shifts			mainIndexView		2
    notifications		mainAdminBox		1
    
    This would be saved into a $plugins array in the Main_Controller. The rank is the order that each model should be rendered for that section (so notifications would be rendered ahead of shifts for the mainIndexView).
  4. The Main_Controller creates $this->template->main = new View('main/index').
  5. The Main_Controller does a foreach ($plugins as $plugin)
    1. A new $plugin['model']_Model is created for each plugin.
    2. $plugin['model']->$plugin['section'] is run, and passed $this->template->main->$kohana_local_data (an Array that Kohana uses to store any variables in the view, which might be variables a plugin needs to do its job or limit its range), and the results are stored in a temporary variable, $data.
    3. A new view is created for that Model and Section, and stored temporarily: $this->template->main->temp = new View($plugin['model'].'/'.$plugin['section'])
    4. The data is stored temporarily as well: $this->template->main->temp->data = $data;
    5. The view is rendered, and this rendered content is appended to any already existing rendered content: $this->template->main->$plugin['section'] .= $this->template->main->temp->render();
  6. The entire view is rendered, with all of the plugin views stored in their section names. So there'd be a $mainIndexView variable and a $mainAdminBox variable passed to the Main view. The Main view would echo these variables at certain locations as it chooses, which would result in any plugin data. It can also completely ignore the variables if it's decided a certain section is no longer needed.

So I once again turn to the wise sages of this thread to offer me thoughts on how this all looks. It finally feels like something that isn't that complex, but is also quite flexible. The only real rules are that the section names have to be maintained across all of these different controllers/models/views- the mainIndexSite section has to be specified in the controller, echo'd in the view, and be a function in the external plugin.

The only thing I'm stumped on is how to incorporate plugins that have plugins. So, say, for the Shifts plugin data, say the ShiftSwitches plugin plugs into Shifts and gives a user the option to give the shift away to other people. So the ShiftSwitches plugin would be plugged into the Shifts plugin, which would be plugged into the Main page. I haven't really given it much thought, but I can already tell it's going to be quite complicated.

KuruMonkey
Jul 23, 2004

mpeg4v3 posted:

So I once again turn to the wise sages of this thread to offer me thoughts on how this all looks.

I'm just going to play devil's advocate here:

Are you really SURE you're not better off using something like Joomla / Drupal / Wordpress / MovableType / CMS of your choosing - that already has a plugin system, a template system etc and a nice simple method for managing the basic content for a site?

And then spending your time writing the actual plugins/widgets to customise that to do what your specific project needs? Remembering that plugins to a CMS don't have to only read their data from the CMS' own database...

Just, you seem to be saying "I think I want some sort of round, sort of easy-rolling type of thing to make moving my stuff around easier - does my new and unique design look sensible?"

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I have this in a script:
php:
<?
if(!function_exists('common_error_reporter')){
    echo 'goddamit';
    function common_error_reporter($errMsg,$error_id){
        die('ERROR '.print_r(debug_backtrace(),true).' ERROR');
    }
}
?>
'goddamit' appears in the output when I run the script (0) that includes the script (1) that this chunk of code lives in and a different script (2) that calls the error reporter. A function from in script 1 is called from script 0 and then calls a function living in script 2 which tries to call common_error_reporter, but PHP throws an error about the error reporter not being defined. The PHP error was actually just as helpful because it told me where script 1 shat itself, but I'm still confused as to why the stupid error reporter didn't exist. Is the function somehow scoped to script 1 when it's conditionally defined? is this hopelessly unclear without a diagram?

mindphlux
Jan 8, 2004

by R. Guyovich
I'm not sure if this is really the place to ask this, but I know more php, SQL and css than I do JS or ASP or anything else really, so...

after doing "IT consulting" (ie, helping poor saps for way too little money) for a number of years, I've decided finally to brand myself and start a webpage and advertising to try to rake in more clients.

as part of this website (using silverstripe as my main CMS), I want to throw up a page where people can play around with customizing brand new computers. basically, like dell or whatever the gently caress, I want to give users several dropdown fields with options that add or subtract from a total price (and change a picture) that's also displayed somewhere on the page, as they go. then, finally, I want them to be able to generate either a PDF, or a simple e-mail "quote" for their system, which they can send to me and be like "look this is sort of what I want, lets talk".

I just don't know what the best way to do this would be. Are there any existing pre-coded things that would handle this that I could just drop in (that might play nice with silverstripe?) Should I just set up an e-commerce package without the actual commerce aspect? Should I bother making this at all database-driven? (there will be lots of options and several base configurations to change - so ease of price/option updating is a factor..)

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

mindphlux posted:

as part of this website (using silverstripe as my main CMS), I want to throw up a page where people can play around with customizing brand new computers. basically, like dell or whatever the gently caress, I want to give users several dropdown fields with options that add or subtract from a total price (and change a picture) that's also displayed somewhere on the page, as they go. then, finally, I want them to be able to generate either a PDF, or a simple e-mail "quote" for their system, which they can send to me and be like "look this is sort of what I want, lets talk".

Where will you be getting the data that drives what options are available and how much they cost? It seems like there will be waaay too much overhead to make something like this worth doing.

I would just make a few different static configurations (budget computer, power user, gaming rig, etc) and show the specs/price comparison and just say that they can be customized to fit your needs. Even then you are still stuck with having to update these configurations every x weeks as price/parts change.

Baz
Jul 27, 2003
Go with the Internet service provider that keeps more Australians online. BigPond.
Does anyone have any experience with the Yii framework and have any opinions on it?

mindphlux
Jan 8, 2004

by R. Guyovich

fletcher posted:

Where will you be getting the data that drives what options are available and how much they cost? It seems like there will be waaay too much overhead to make something like this worth doing.

I would just make a few different static configurations (budget computer, power user, gaming rig, etc) and show the specs/price comparison and just say that they can be customized to fit your needs. Even then you are still stuck with having to update these configurations every x weeks as price/parts change.

I will be making the prices up, so I guess just a text file?

You're right though, the more complicated part of all that really isn't worth doing. I'll just price a couple generic systems and say they can be customized. Why do I have to make things more complicated than they have to be?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

What's a good way to obfuscate my links without giant overhead/killing MySQL?

Right now I have links like move.php?sector=42 and would prefer something a bot can't easily read like action.php?whatever=HASH_GOES_HERE

The hashes should change whenever a player uses one...

Any ideas?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

drcru posted:

What's a good way to obfuscate my links without giant overhead/killing MySQL?

Right now I have links like move.php?sector=42 and would prefer something a bot can't easily read like action.php?whatever=HASH_GOES_HERE

The hashes should change whenever a player uses one...

Any ideas?

Can you describe the problem you are trying to solve a bit more?

It sounds like you should be using a POST instead of a GET to do whatever those links are doing, based on how you have named them. Either way it should be validating the "move" you are making server side. I should be able to tell it to do every move, but the only ones it actually does are the valid ones.

spiritual bypass
Feb 19, 2008

Grimey Drawer

drcru posted:

What's a good way to obfuscate my links without giant overhead/killing MySQL?

Right now I have links like move.php?sector=42 and would prefer something a bot can't easily read like action.php?whatever=HASH_GOES_HERE

The hashes should change whenever a player uses one...

Any ideas?

Maybe you could make those links come out on the page as md5($sectorID), and then
SELECT * FROM Sectors
WHERE md5(sectorID) LIKE ?

That would obscure the actual sector IDs and would prevent users from guessing them. Of course, a bot playing your game could still scrape them off the page and play the game, but maybe it would prevent guessing.

Don't take this advice verbatim; it's not perfect. You'd at least want to salt those hashes, for starters.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

fletcher posted:

Can you describe the problem you are trying to solve a bit more?

It sounds like you should be using a POST instead of a GET to do whatever those links are doing, based on how you have named them. Either way it should be validating the "move" you are making server side. I should be able to tell it to do every move, but the only ones it actually does are the valid ones.

Right now, I have plain html links like this:
<a href="./move.php?sector=42">#42</a>

I want them to be something like this:
<a href="./action.php?cmd=HASHED_VALUE">#42</a>

move.php right now basically is this:
$sector = intval(stripslashes($_REQUEST['sector']));

rt4 posted:

Maybe you could make those links come out on the page as md5($sectorID), and then
SELECT * FROM Sectors
WHERE md5(sectorID) LIKE ?

That would obscure the actual sector IDs and would prevent users from guessing them. Of course, a bot playing your game could still scrape them off the page and play the game, but maybe it would prevent guessing.

Don't take this advice verbatim; it's not perfect. You'd at least want to salt those hashes, for starters.

Something like this could work since we already have a hash stored for the current session but that might not be enough if we want a new hash every move, right? Don't exactly want to update the session table every time we move though so hmm.

edit: Also thanks for the replies guys.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

drcru posted:

Right now, I have plain html links like this:
<a href="./move.php?sector=42">#42</a>

I want them to be something like this:
<a href="./action.php?cmd=HASHED_VALUE">#42</a>

What exactly does this solve though? Are you trying to prevent them from just changing the link to sector=43?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

fletcher posted:

What exactly does this solve though? Are you trying to prevent them from just changing the link to sector=43?

That's basically it.

Right now I'm trying to make a hash like this:

code:
$sector = 999;
$hash = base_convert($sector, 10, 36);
echo intval($hash, 36) . '<br />';
This works but when I run it with $sector = log10(999) it doesn't return the right answer. Seems like a math error on my part but I can't think anymore :(.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

drcru posted:

That's basically it.

Right now I'm trying to make a hash like this:

code:
$sector = 999;
$hash = base_convert($sector, 10, 36);
echo intval($hash, 36) . '<br />';
This works but when I run it with $sector = log10(999) it doesn't return the right answer. Seems like a math error on my part but I can't think anymore :(.

Check out the php crypt/mcrypt stuff.

Still though, what is bad about them changing it to sector=43? What makes this an invalid "move"? When they try to feed it sector=43, why can't the server determine that is not a valid move and just not perform it?

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

fletcher posted:

Check out the php crypt/mcrypt stuff.

Still though, what is bad about them changing it to sector=43? What makes this an invalid "move"? When they try to feed it sector=43, why can't the server determine that is not a valid move and just not perform it?

I'll take a look at it, thanks. And the server already knows if it's a valid move or not, I just don't want them to be able to make the move without clicking a link.

spiritual bypass
Feb 19, 2008

Grimey Drawer

drcru posted:

I'll take a look at it, thanks. And the server already knows if it's a valid move or not, I just don't want them to be able to make the move without clicking a link.

In that case, maybe you should use JavaScript instead of anchors. A bot will always be able to scrape those links.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

rt4 posted:

In that case, maybe you should use JavaScript instead of anchors. A bot will always be able to scrape those links.

drcru posted:

I'll take a look at it, thanks. And the server already knows if it's a valid move or not, I just don't want them to be able to make the move without clicking a link.

Short of a good CAPTCHA, a bot will be able to do pretty much anything a human could do on your site. Doesn't really matter if you use anchors or js. Also, a bot can click on a link to move.php?sector=42 just as easily as action.php?sector=SOMESCARYHASH so that really does nothing.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

fletcher posted:

Short of a good CAPTCHA, a bot will be able to do pretty much anything a human could do on your site. Doesn't really matter if you use anchors or js. Also, a bot can click on a link to move.php?sector=42 just as easily as action.php?sector=SOMESCARYHASH so that really does nothing.

True, hm. I guess I'll just deal with the bot issue if this thing ever gets popular enough for someone to want to use a bot.

Thirteenth Step
Mar 3, 2004

Im just trying to wrap my head around sessions... (fairly new to this) I'm not sure I've got it right though.

I have a multi-page site which begins with a log-in page. When a user successfully logs in I want a session to be created, then they will be free to browse the rest of the sites private pages without problem.

If the user tries to manually navigate to one of the post-login pages without logging in first, I want the site to realise no session has been created (ie, user has not logged in before-hand) in and redirect them to a rejection page inviting them to register.

Below is the code im using to create the session, although im not sure if this should go on my initial post-login page as the users could simply direct to this page and have the session create itself without the need for login.

php:
<?php
session_start();

$_SESSION['loggedin']="private";

?>

and below is the snippet of code I am using (or trying to use) to detect if a session is active, if a session is not active then direct to register.php.

php:
<?php
if (defined('SID'))
        {
        "do nothing" // I dont actually know
        }
else
        {
        header("Location: please_register.php");
        }
?>

I know i've gone about this in a bit of a mad way, don't suppose anyone could clear this up for me? Thanks!

Innominate
Sep 2, 2004
The Innominate

Thirteenth Step posted:

Im just trying to wrap my head around sessions... (fairly new to this) I'm not sure I've got it right though.

I have a multi-page site which begins with a log-in page. When a user successfully logs in I want a session to be created, then they will be free to browse the rest of the sites private pages without problem.

You're confusing sessions with logins. All a session does is store data about a user on the server, and links it with the user using a cookie. For tracking if someone is logged in, you would store that data within a session, not track the sessions existence.

When sessions are in use, a new visitor is automatically assigned a new session when your page calls session_start(). session_start() doesn't so much create a new session as say "this page is going to use sessions."(And creates one if one doesn't exist) It needs to be called before sessions can be used in any way, so when sessions are in use you simply assume there is always a session active.

Working with sessions is really mind bogglingly easy, see the example at: http://us.php.net/session_start

php:
<?php
session_start();

if ( $_SESSION['loggedin'] == 'private' ) {
    // logged in
} else {
    // not logged in
}
?>

Innominate fucked around with this message at 03:06 on Mar 25, 2010

Thirteenth Step
Mar 3, 2004

Innominate posted:

For tracking if someone is logged in, you would store that data within a session, not track the sessions existence.

Ah ha, Thats the bit thats thrown me then, it's been a while :ohdear: thanks for the quick reply!

I'll have a look in the manual and see if I can find out the next step.

Thanks!

Adbot
ADBOT LOVES YOU

Thirteenth Step
Mar 3, 2004

got it (i think):

php:
<?php
    if(!isset($_SESSION["username"])) {
    header("Location: denied.php");
    exit;
   } 
?>

Seems to work. :)

("username" is the session created in the previous page's login form, upon successful login)

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply