CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 87 users online: 2 members, 60 guests and 25 bots.
Members: tiago94.
Bots: Magpie Crawler (5), Googlebot (19), MSN/Bing (1).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
    » Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8
» View previous topic :: View next topic  
Author Message
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55741
Location: Earth, Sol, Milky Way

Posted: 05 Sep 2008 12:32:34 pm    Post subject:

Haha, it's one of those stupid little errors; you have all the Regex stuff correct. Change:

Code:
preg_replace($rep, $rep1, $temp);
to
Code:
$temp = preg_replace($rep, $rep1, $temp);

_________________


Back to top
lafferjm


Calculator Deity


Joined: 14 Mar 2006
Posts: 1528
Location: at my house

Posted: 05 Sep 2008 12:41:44 pm    Post subject:

Thanks again Kerm. Now that Kerm finished this project for me Rolling Eyes . Does anyone have any other projects ideas that i can try to work on? Laughing
_________________

Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55741
Location: Earth, Sol, Milky Way

Posted: 05 Sep 2008 12:50:44 pm    Post subject:

Well, just as a stylistic nitpick, I'd like to improve
Code:
$rep[0] = "/&r/";
$rep[1] = "/&b/";
$rep[2] = "/&Y/";
$rep[3] = "/&c/";
$rep[4] = "/&R/";
$rep[5] = "/&B/";
$rep[6] = "/&O/";
$rep[7] = "/&w/";
$rep[8] = "/&g/";
$rep[9] = "/&c/";
$rep[10] = "/&p/";
$rep[11] = "/&z/";
$rep[12] = "/&G/";
$rep[13] = "/&W/";
$rep[14] = "/&P/";
to
Code:
$rep = array("/&r/","/&b/","/&Y/","/&c/","/&R/","/&B/","/&O/","/&w/","/&g/","/&c/","/&p/","/&z/","/&G/","/&W/","/&P/");

_________________


Back to top
lafferjm


Calculator Deity


Joined: 14 Mar 2006
Posts: 1528
Location: at my house

Posted: 25 Jun 2012 06:30:50 pm    Post subject:

So once again I have begun working with php. I am not trying to do anything spectacular, just playing around with sessions. But I have run into an issue that I know one way of solving but was curious as to whether or not there is a better way. My code is as follows:

Code:

<?php
    session_start();
    require_once("../includes/db.php");

    //If user name is set they are logged in   
    if(isset($_SESSION['username'])) {
   
        //If userlevel is not 0 then they are not an admin and need to leave   
        if($_SESSION['userlevel'] != 0) {
            die("Sorry you do not have permission to be here.");
        }
   
        //If we get here they are an admin and we can do stuff 
        echo "Welcome to the admin area " . $_SESSION['username'] . ".";

        //Now we need to connect to the database so that we can retrieve all users
        mysql_connect(DB_HOST,DB_USER,DB_PASS) or die("Could not connect to database");
        mysql_select_db(DB_NAME) or die("Could not select database");

        $query="SELECT * FROM members WHERE userlevel='1'";
        $rows=mysql_query($query);

        echo "<table border='1px'>";
   
        while($results=mysql_fetch_array($rows)) {
            echo "<tr>";
            echo "<td>" . $results['username'] . "</td>";
            echo "<td><a href='" . $_SERVER['PHP_SELF'] . "?action=promote&user=" . $results['username'] . "'>promote</a></td>";
            echo "</tr>";
        }
       
        echo "</table>";

    } else {
        echo '<div>You must login first.  Please click ';
        echo '<a href="../index.php">here</a>';
        echo ' to login.</div>';   
    }
?>


$_SERVER['PHP_SELF'] points to itself(http://localhost/~lafferjm/login/admin/admin.php?. Which is close to what I want, but instead of admin.php I want actions.php. I know document_root could work, but with me using userdir, it doesn't work correctly. Another solution would be just to hardcode the url but I wish to avoid that. The solution that I have thought of involves simple string processing to get the root, but it seems as though there should be a bit of an easier way.

EDIT: After making the post I figured maybe the error was with the way userdir was configured and found a solution via that route. In the above code I replaced

Code:
echo "<td><a href='" . $_SERVER['PHP_SELF'] . "?action=promote&user=" . $results['username'] . "'>promote</a></td>";

with

Code:
echo "<td><a href='" . dirname($_SERVER['PHP_SELF']) . "/actions.php?action=promote&user=" . $results['username'] . "'>promote</a></td>";
and all is well.
_________________

Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55741
Location: Earth, Sol, Milky Way

Posted: 25 Jun 2012 06:45:52 pm    Post subject:

Yup, that's the solution that I was about to suggest before I saw in SAX that you had edited your post. Smile Nice job on the four-year necrobump on your own thread with relevant content, which might be a record. Of course, feel free to post if you have further questions or thoughts.
_________________


Back to top
lafferjm


Calculator Deity


Joined: 14 Mar 2006
Posts: 1528
Location: at my house

Posted: 26 Jun 2012 10:24:32 pm    Post subject:

Will do. I am going to attempt to recreate the same thing but with an oo approach, because I can see how the procedural way can get ugly fast. I also want to try and learn a little about pdo. And as a side note from reading my previous posts I must have been an annoying little a back in the day.
_________________

Back to top
lafferjm


Calculator Deity


Joined: 14 Mar 2006
Posts: 1528
Location: at my house

Posted: 29 Jun 2012 06:04:07 pm    Post subject:

Alright so I have rewritten the entire thing using pdo. My next attempt will be using objects. After the first login I will build the user object with the retrieved data. My question is, should I store this data in a session or should I run the query and rebuild the object on every page?
_________________

Back to top
allynfolksjr


Minor Calculator Deity


Joined: 20 Apr 2005
Posts: 1273

Posted: 30 Jun 2012 01:45:42 am    Post subject:

Run from PHP. Runnnn.
_________________
http://tcpa.calcg.org/
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55741
Location: Earth, Sol, Milky Way

Posted: 01 Jul 2012 07:27:03 am    Post subject:

lafferjm wrote:
Alright so I have rewritten the entire thing using pdo. My next attempt will be using objects. After the first login I will build the user object with the retrieved data. My question is, should I store this data in a session or should I run the query and rebuild the object on every page?
There's nothing wrong with storing everything in sessions, and since it's easier, I say that you do that.
_________________


Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    » Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8
» View previous topic :: View next topic  
Page 8 of 8 » All times are GMT - 5 Hours

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.040076 seconds.