Jump to content
Larry Ullman's Book Forums

Antonio Conte

  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by Antonio Conte

  1. phpBB3 sets the $user object behind the scenes. The code is all over the place, so it's not easy to follow the logic. I don't need to post any data to make the original script work (As you can see be logging into the example account), but I would guess that's because of the cookies keeping the login active. Due to that, I think I might need to attach a cookie. I'm not really sure how that is done, if there's sub-domain issues involved, where the cookie is located, etc.
  2. 1. Open the file using fopen() (Check for a GET request from the form you have a button in) 2. Read through the file and assign it to an array 3. Pop the last (or first, but that'll be slower) element from the array 4. Use the email() function to send it where it should 5. Write the array back to the file 6. Close the file Search for how to handle these problems, and you should be able to make it work quite quickly.
  3. Hey, everyone I'm trying to bind together two systems. The first one is a membership system running on Laravel and the other is the forum solution phpBB3. (Similar to iPB, the forum solution here) The membership system should do a cURL request against a simple script added to phpBB3. The script uses phpBB3s session solution to make sure a user is logged in. If that is true, information about the user will be returned. If that is false, anonymous user information is returned. The return source is JSON. You may login to a test account here: Username: example Password: example phpBB3-script: - http://forum.juvenorge.com/getLoggedInUserInfo.php <?php define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : $_SERVER['DOCUMENT_ROOT'] . '/'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); // Start session management $user->session_begin(); $auth->acl($user->data); $user->setup(); // Build a new array to only retrieve needed data $data = array( 'user_id' => $user->data['user_id'], 'username' => $user->data['username_clean'] ); echo json_encode($data); The script will return the JSON string {"user_id":"1","username":"anonymous"} for you guys as standard. If you login using the attached User info, the output should be {"user_id":"1210","username":"example"} Laravel Controller method: - http://medlem.juvenorge.com/innmelding $ch = curl_init('http://forum.juvenorge.com/getLoggedInUserInfo.php'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $output = curl_exec($ch); curl_close($ch); return $output; However, the Laravel controller returnes the anonymous user data instead of my own data, even when logged in. I think this may be due to some checks that phpBB3 implements for security reasons. phpBB3 saves cookies to the key "phpBB3_****" where the asterix represent a secure key. There are three cookies saved in total: Cookies: [phpBB3_****_u] => X [phpBB3_****_k] => ************* [phpBB3_****_sid] => ********************* What do I have to do to be able to perform the cURL request properly? Really hoping for some help here. Thanks in advance.
  4. If you are just going to merge them without doing anything else, why not build a single array instead?
  5. The server requires a restart for it to take affect. It's most likely that. Ini_set() overwrites your php.ini for the duration of the script btw.
  6. The easiest solution is through PHPMyAdmin. If your on a hosting provider with cPanel, your guaranteed to have that. You might have it non-the-less, but if not, I would just change my provider. It's such a basic tool for DB administration you shouldn't really accept to be without. This holds true even if you are a Python or Ruby developer from my experience.
  7. Contact your host, and they will most likely give one to you. If you have a shared host, some of the cheaper providers might not give you the option, though. You don't really "write code" for a php.ini. You do it occasionally as you need things to work, but then you ignore it for long periods of time. I've changed a php.ini file about five times over the last three years myself. If you need something to change, I would just email my hosting provider and let them take care of it.
  8. The error message is clear cut here. The table "myquote" in the DB "myquotes" does simply not exist. Make sure both the DB and the table is correct.
  9. Good to know. It was a somewhat educated guess, but I've myself started developing a membership system with a similar approach. There exists four membership types in total, and a single user may hold zero to three of these memberships. Each membership requires different data, and all of them are based on seasonal renewal. Up to three family memberships may also be tied to a specified JCN membership, but these cannot be purchased alone. Since the system requires authentification, a basic user type (That'll be Laravel's basic auth table here) is required. I'll share my table structure here: seasons ( id, name, validFrom, validThrough ) users ( id, username, password, firstname, lastname, phone, mobile ) premiums ( id, user_id*, season_id*, membercode ) subscribers ( id, user_id*, season_id*, section, row, seat ) jcn ( id, user_id*, season_id, address, province, postal, zip ) family ( id, jcn_id, user_id, season_id ) Understroke: Primary key Asterix: Foreign key This is a very complicated memberships systems, and few will hold a premium or subscriber membership. I don't know if this will help you at all, but rename users to persons and subscribers and premiums with student and employee, and you have a basic structure to build on. You'll obviously need to change the data the table holds.
  10. Don't confuse addresses allocation with size. Some bits of the total size is used for meta data and similar things like pointers, etc. The size is an indication of the total amount of data you can save to the type, not how much size is used in total. You can compare this to HTTP headers, or something else you are familiar with. One reasons why the array might allocate closer using less bytes, is that it can possibly ignore saving lots of redundant meta data. I don't really know how C++ functions from a lower level programming standpoint, but such optimizations are normally done behind the scenes. To summarize, a single long and an array of longs still has the same capacity (4 bytes) but an array optimizes meta data in some way, allowing for closer memory addresses.
  11. No problem. I'm not really familar with C+, so I can't share to much besides general programming knowledge. The reason why I talked about size and length wasn't to be pedantic with you, but to tell you that length() will yield wrong results. (Considering what you want) I noticed at least String has a capacity() member that should return the size, but I'm not familiar enough with the manual to find if that's true for the other types. If you don't use the member length(), ignore this. After some searching, I found a Stack Overflow post related to your information seeking. It seems the size of the types are dependent on both compiler, architecture and OS, as an Int can range from 4 to 8 bytes. I would take a strong guess that the same is true for long. Also, I tried to explain why a sign and unsigned version of long won't differentiate in size. This is pretty common in language design, so I would guess C++ implements numbers the same way as Java or C#. Read my explanation one more time about that. Did that answer anything? I'm sure Larry will get around to this one eventually.
  12. It seems to me you mix up the terms size and length. Length will give you the number of characters of the object. Regarding signed vs unsigned, you need to think of numbers as a closed circle, not a straight line. An unsigned version of the type will therefor allow you to utilize larger numbers on the scale, while a signed version allocated negative numbers instead. If you have ever touched PHP, you will see a constant called MAX_INT. That is the largest possible number allowed for the datatype Integer. If a larger number is assigned, you'll get something called Integer Overflow, and the number will instead be saved as a float. That kind of conversions between types are common. Reading more about basic data types will give you a lot.
  13. This is the classic Object-relational impedance mismatch problem you are facing here. My first though is that if you can avoid using several tables for user data, you get way easier off this problem. One way to solve this is work with a generic "Person" table instead of employees and students, and use foreign keys to join the extra data you need accordingly. (Be it credits for classes or when/where to hold lectures) A flag can be used to differentiate between types of persons, and what kind of object to be created. Will such a solution work out for you?
  14. A simple tip is trying with ini_set() and see if that affects something. You've obviously tried restarting Apache since you changed it? ini_set('display_errors', 1);
  15. The first three questions is done via php.ini or using the set_ini() function. 1. open_basedir - http://www.php.net/manual/en/ini.core.php#ini.open-basedir Normally null. If this is set to a directory, PHP will refuse to open files outside this directory tree using fopen() or similar functions. This can increase security, as a hacker might try to open a password file on your server or include a bad file he has managed to upload on his own. 2. Register_globals - http://www.php.net/manual/en/ini.core.php#ini.register-globals This is depricated and removed in newer versions of PHP. (<= PHP 5.3.0) If this is on, you need to change it in your php.ini. Considering almost everyone is at least on PHP 5.3.0, this is most likely not a problem anymore.@ 3. Sessions directory Sessions are server-side cookies. (Not changeable for a user) However, if you are on shared hosting, like most of us, the session directory is normally shared in something like the folder "tmp". Changing it to a folder only reachable for your user account will theoretically improve security. Listen to what the book says. 4. MySQL access You can normally change this in cPanel, and I think the standard is localhost only. If you develop locally on your computer, adding your IP address will allow you to connect to your DB from local scripts. Assigning "*" will allow you to connect from anywhere. The security is increased when no-one can connect to your DB unless they are on your server, but listen to what the book says. I do allow all connections during development myself.
  16. No problem. I'm on an iPad right now, so I can't check the files until tonight. I suggest you apply some debug techniques. First, echo session_id() before an after invoking read_session() through using $_SESSION. Then try echo out $sid somewhere inside read_session() to make sure you get a value. If those are empty, I would suggest reading more about how session_start(); affects everything and would maybe try to move it around.
  17. Ok. That makes more sense then. All the other functions listed in the handler is obviously defined too? Make sure you don't get any error by including this in the top of one of your files: ini_set('display_errors', 1); error_reporting(-1); One thing I notice is that the callable you define for reading session (ie. read_session()) has to return serialized data. You currently return an array. Try calling serialize($data) where you return the data from your DB. Aka: // Return the data: return serialize($data); This data will be unserialized for you automaticly and will populate the $_SESSION global. However, this callback function needs to be returned serialized.
  18. Ok. That function declaration looks good. How do you call that function? Also, as I said earlier, you cannot use the parameter in session_id() if you want to get the session value. When you do that, you basically set a new session_id for the user. I'm also a little skeptical about you starting the session in the bottom of the file. That might work if everything is encapsulated in functions, but it will fail if you call read_session() before session_start() is called. Try something along these lines where you read the session. // Start session session_start(); // Read session data $session = read_session(session_id()); // Simple debug, remove once working echo '<pre>', print_r($session) , '</pre>';
  19. Ok. I don't own the third edition of the book, so excuse me guessing a little. Could you please post the function here?
  20. Please share your findings. People tend to search problems, so you could be helping out that way.
  21. Remove the param $sid from session_id() and see what that gives you. You should only specify the param when you want to use it as a setter, and leave it blank when using it as a getter function. I might also have misunderstood you, but to get values from a function, you need to return something. Make sure the function looks like this: function read_session() { return session_id(); } Hope that helps you out.
  • Create New...