Jump to content

HDFilmMaker2112

Members
  • Posts

    547
  • Joined

  • Last visited

    Never

Posts posted by HDFilmMaker2112

  1. Then let's try just a new set of rules.

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)(/([^/]+))?/?$ index.php?p=$1&s=$3 [L,QSA]

     

    That does work, but now I'm running into a problem with my login script. If you click the log-in button with not details entered, it changes the top menu links to as if you were logged in; it also redirects back to the log-in form with the error message saying wrong username or password, which it should.

     

    Then if you click on anyone of the links in the top menu, it changes it back to the not logged in menu:

     

    <?php
    session_start();
    $viewed_homepage=$_SESSION['homepage'];
    $login_username=$_POST['email'];
    $login_username=strtolower($login_username);
    $login_password=$_POST['password'];
    $login_stay_logged_in=$_POST['stayloggedin'];
    $login_form_submitted=$_POST['login_form_submit'];
    
    /*if form has been submitted and the front page has been viewed*/
    if($viewed_homepage=="viewed" && $login_form_submitted=="submitted"){
    require_once 'db_select.php';
    require_once 'function.php';
    
    /*Connect to DB*/
    $LoginDB = $db->connect('mysqli', 'persist', 'db418598519');
    
    /*Encode - Sanitize user input for query*/
    $sanitized_email = $LoginDB->mysqli_sanitize($login_username);
    $encoded_password = $LoginDB->kam3($login_password);
    
    /*run query*/
    $result = $LoginDB->query("SELECT * FROM user WHERE email_address='$sanitized_email' AND password='$encoded_password'");
    $num_rows = $result->num_rows;
    $rows = $result->fetch_assoc();
    
    /*Close Database Connection*/
    $LoginDB->close();
    
    /*If user matches a database entry log-in*/
    if(($num_rows==1) && ($rows["email_address"]==$sanitized_email && $rows["password"]==$encoded_password)){
    
    /*Set Session/Cookie data to stay logged in*/
    $_SESSION['username']=$sanitized_email;
    $_SESSION['password']=$encoded_password;
    $_SESSION['user_id']=$rows['id'];
    
    /*If selected, Set Cookies*/
    if($login_stay_logged_in=="yes"){
    /*Connect to DB to insert cookie key*/
    $CookieDB = $db->connect('mysqli', 'persist', 'db418598519');
    
    /*Generate key, encode username, and get current time for cookies */
    $hased_value = kam3(md5(generatepassword(6)));
    $hashed_username = md5s($rows["email_address"]);
    $time = time();
    setcookie("knxn_hash", $hased_value, time()+(86400*180), "/", "beta.area51entertainment.com",false,false);
    setcookie("knxn_username", $hased_username, time()+(86400*180), "/", "beta.area51entertainment.com",false,false);
    setcookie("knxn_visited", $time, time()+(86400*180), "/", "beta.area51entertainment.com",false,false);
    }
    
    /*Unset error alert for log-in form*/
    unset($_SESSION['login_error']);
    
    /*redirect to dashboard*/
    header("Location: /home");
    }
    else{
    /*redirect to index.php with error message*/
    $_SESSION['login_error']="error";
    header("Location: /");
    }
    }
    else{
    /*redirect to index.php if submission didn't originate from log-in form on index.php*/
    header("Location: /");
    }
    ?>
    

     

    The top menu changes just based on whether or not the variable $_SESSION['username'] is set or not.

  2. It's because of this:

     

    RewriteRule . index.php [L]

     

    But I need that for my homepage to show. Otherwise I always get another page:

     

    /*This always executes because the other rewrite always generates a p= . For some reason it executes even when the requested page is the domain name with no additional information in the address bar. So http://www.kynxin.com/ loads a blank profile page*/
    elseif(isset($_GET['p']) && $_GET['p']!=null && $_GET['p']!=""){ 
    $url=$_GET['p'];
    $content.='
    <div class="left profile_left_width">
    <div class="profile_photo_details_wrapper">
    <div class="profile_photo">
    Profile Photo
    </div>
    <div class="profile_details">
    Profile Details
    </div>
    </div>
    <div class="profile_activity">
    </div>
    </div>
    <div class="right profile_right_width">
    <div class="profile_cover">
    Cover Photo
    </div>
    <div class="profile_mystream">
    Status Updates
    </div>
    </div>
    ';
    }
    
    /*Default page - Front Page*/
    else{
    //Front page code
    }
    

  3. And that's also not working for my login form. I can't use an absolute path in my forms HTML (because it just stacks on top of my domain name); and if I use /login.php, when I submit the form it just reloads the page that I was just on, and shows /login.php in the address bar.

     

    See for yourself: http://www.kynxin.com/ click the login button. It'll just reload the same page and add /login.php into the address bar.

  4. Alright, got the rewrite issue fixed.

     

    logout.php is still not logging out. As a matter of fact no .php files are loading correctly.

     

     

    Options -MultiViews
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_URI} !((.*).(js|css))$ [NC]
    RewriteRule . index.php [L]
    RewriteCond %{REQUEST_URI} !((.*).(js|css))$ [NC]
    RewriteRule ^([A-Za-z0-9#_\.\$\)\(\*\^]+)/?$ index.php?p=$1 [QSA,L,NC]
    RewriteCond %{REQUEST_URI} !((.*).(js|css))$ [NC]
    RewriteRule ^([A-Za-z0-9#_\.\$\)\(\*\^]+)/([A-Za-z0-9_]+)/?$ index.php?p=$1&s=$2 [QSA,L,NC]
    
    

  5. Also, now after trying the above rewrite code, my logout page won't log me out. Worked fine prior.

     

    <?php
    session_start();
    
    /*Unset and destroy users session data*/
    if(isset($_SESSION['username'])){
    unset($_SESSION['username']);
    unset($_SESSION['password']);
    unset($_SESSION['user_id']);
    unset($_SESSION['homepage']);
    session_destroy();
    
    header("location: ./");
    }
    else{
    header("location: ./");
    }
    ?>
    

  6. I know this isn't the right sub-forum, but this is urgent the Apache sub-forum hardly gets any views.

     

    This rewrite is cause all of my css and javascript files not to load.

     

    Even my home page http://www.kynxin.com/ doesn't load it's style sheets.

     

    Options -MultiViews
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_URI} !((.*).(js|css))$ [NC]
    RewriteRule . index.php [L] [OR]
    RewriteRule ^([A-Za-z0-9#_\.\$\)\(\*\^]+)/?$ index.php?p=$1 [QSA,L,NC] [OR]
    RewriteRule ^([A-Za-z0-9#_\.\$\)\(\*\^]+)/([A-Za-z0-9_]+)/?$ index.php?p=$1&s=$2 [QSA,L,NC]
    

  7. I really don't want to put the connect function on each page so I usually create a db.php and just include the file. It there a way to do it with the connection variable on mysqli instead.

     

    For example, client A:

    include('db.php');
    
    mysqli_query($clientA, "SELECT * FROM test;");
    

    ClientB

    include('db.php');
    
    mysqli_query($clientB, "SELECT * FROM test;");
    

     

    Is there a way to set the $conn name based on session data?

     

    ??

     

     

    You can just do this:

     

    db.php

    <?php
    session_start();
    
    $clientid = $_SESSION['clientid']; //Get set session with index of "clientid". Ever where this is included it will run and look for the value of the session "clientid".
    
    $db_name="db_".$clientid; //Generate db name from current client, via the clientid variable set from the clientid session
    
    $db = mysqli_connect('localhost', 'fake_user', 'my_password', $db_name); // connect to DB using generated db name.
    ?>
    

     

    <?php
    include 'db.php';
    $sql = mysqli_query($db, "SELECT * FROM test");
    ?>
    

     

    When you include a file you're essentially including the raw contents of it, in the exact position where it's called.

     

    If you were able to see the pure code of the combined file:

     

    This:

    <?php
    include 'db.php';
    $sql = mysqli_query($db, "SELECT * FROM test");
    ?>
    

     

    Would actually look like this:

     

    <?php
    session_start();
    
    $clientid = $_SESSION['clientid']; //Get set session with index of "clientid". Ever where this is included it will run and look for the value of the session "clientid".
    
    $db_name="db_".$clientid; //Generate db name from current client, via the clientid variable set from the clientid session
    
    $db = mysqli_connect('localhost', 'fake_user', 'my_password', $db_name); // connect to DB using generated db name.
    ?>
    
    <?php
    $sql = mysqli_query($db, "SELECT * FROM test;";
    ?>
    

  8. I am working on an application and I wanted it to be a single app with a database for each client. What is the best way to do this? I've tried setting the DB connection using a variable, but it doesn't work.

     

    Example:

    <?php
    session_start();
    
    $_SESSION['clientid'] = "clientA";
    
    $db = $_SESSION['clientid'];
    
    $clientA = @mysqli_connect('localhost', 'fake_user', 'my_password', 'db_clientA');
    
    $clientB = @mysqli_connect('localhost', 'fake_user', 'my_password', 'db_clientB');
    
    $sql = mysqli_query($db, "SELECT * FROM test;";
    ?>
    

     

     

     

    <?php
    session_start();
    
    $_SESSION['clientid'] = "clientA";
    
    $clientid = $_SESSION['clientid'];
    
    $db_name="db_".$clientid; //Just my coding style, you could also do $db_name="db_$clientid"; If you're okay with a hybrid variable and string inside the same quotes. 
    
    $db = mysqli_connect('localhost', 'fake_user', 'my_password', $db_name);
    
    $sql = mysqli_query($db, "SELECT * FROM test");
    ?>
    

     

    If I'm not mistaken, they way you had it you would open two MySQL connections, but you'd only ever be using one of them. Major waste of server resources; and if you add more clients, it would just be a nightmare, and possibly a MySQL server crash, due to overload.

  9. I can't get my css file to link correctly after moving the CSS file call into another PHP file and including it into my main page. The file seems to get included into display.php because the top menu bar is styled correctly; however, the content pulled in via pages.php doesn't have the css applied to it.

     

     

    display.php

    <?php
    if(isset($_SESSION['homepage'])){
    ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" id="kynxin">
    <head>
    <base href="http://kynxin.com/" />
    <title>Kynxin<?php echo " $section"; ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="verify-v1" content="" />
    <meta name="keywords" content=""  />
    <meta name="description" content="" />
    <meta name="author" content="Kynxin Development Team" />
    <meta name="robots" content="index, follow" />
    <?php
    echo $css_header;
    ?>
    <link rel="stylesheet" href="style.css" media="screen" />
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.area51entertainment.co/TouchIcon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.area51entertainment.co/TouchIcon.png" /> 
    <link rel="image_src" href="./logo.png" /> 
    <script src="float.js"></script>
    <script src="ajax.js"></script>
    </head>
    <body>
    <div class="wrapper">
    <div id="header_float">
    <div class="header_wrapper">
    <div class="logo">
    <a href="./">Kynxin</a>
    </div>
    <?php
    /*Generate menu array*/
    $menu_array = array();
    $menu_array['loggedin'] = array("Home" => "/home", "Stream" => "/newsstream", "Notes" => "/notifications", "Req" => "/requests", "Msgs" => "/messages");
    $menu_array['loggedout'] = array("Music" => "/music", "Movies" => "/movies", "Television" => "/television", "Games" => "/games", "Videos" => "/videos", "Browse People" => "/people");
    $search['menu_items']=array("People" => "people", "Music" => "music", "Movies" => "movies", "Television" => "television", "Games" => "games", "Videos" => "videos");
    
    /* logic to determine which menu to use*/
    if(isset($_SESSION['username'])){ $type = 'loggedin'; } 
    else { $type = 'loggedout'; }
    
    /*Search Form*/
    $search_form='<form>
    <fieldset class="search_box">'."\n";
    $search_form.=menu($search['menu_items'], "select")."\n";
    $search_form.='<input type="text" name="search_input" id="search_input" placeholder="Search for..." /> <input type="submit" value="Go" name="search_go" id="search_go" /> <!--Launch Music Player-->
    </fieldset>
    </form>';
    
    /*Links Wrapper*/
    echo '<div class="links';if($type=="loggedout"){ echo '2'; } echo '">',"\n";
    echo menu($menu_array[$type]);
    echo "</div>","\n";
    if($type=="loggedin"){
    echo '<div class="links_search">',"\n",
    $search_form.'
    </div>',"\n",
    '<div class="links_right">
    Profile Link/Settings/<a href="./logout.php">Sign-Out</a>
    </div>',"\n"; 
    } 
    elseif($type=="loggedout"){
    echo '<div class="links_right2">',"\n",
    $search_form,"\n",'</div>',"\n"; 
    }
    echo'</div>
    </div>
    <!--[if lt IE 7]> 
    <div style=\' clear: both; height: 59px; padding:0 0 0 15px; position: relative; top: 37px;\'> 
    <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
    <img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." /></a>
    </div> 
    <![endif]--> 
    <noscript>
    <div class="javascript">
    <div class="javascript_wrapper">
    We\'ve noticed you have Javascript turned off. <br /> While it\'s not absolutely required to have Javascript turned on to use our site; it is highly recommended.
    </div>
    </div>
    </noscript>',"\n";
    content_wrapper($switch,$content);
    echo '</div>',"\n",$footer;
    }
    else{
    header("Location: ./");
    }
    ?>
    </body>
    </html>
    

     

    index.php in root:

    <?php
    require_once 'pages.php';
    require_once 'display.php';
    $_SESSION['homepage']="viewed";
    ?>
    

     

    index.php in signup folder:

    $css_header='<noscript>
    <style type="text/css">.hide{display: none;}</style>
    </noscript>'."\n".'<link rel="stylesheet" href="/signup/signup_style.css" media="screen" />'."\n";
    
    $footer='<script src="membership.js"></script>'."\n";
    if(isset($_SESSION['register_membership_type'])){
    $onload_session = $_SESSION['register_membership_type'];
    $onload_session = preg_replace("/\r?\n/", "\\n", addslashes($onload_session));
    }
    else{
    $onload_session="basic";
    }
    $footer.='<script type="text/javascript">'."\n".
    "changeButton('$onload_session');"."\n".
    "</script>\n".
    '<div id="register_day_store"></div>'."\n".
    '<div id="register_month_store"></div>'."\n";
    require_once '../display.php';
    ?>
    

  10.  

    For some reason I had to insert{ }

     

    You mean after the switch condition, and the end of the switch; like this:

     

    switch ($month){
    case "jan":
    $data="content here";
    break;
    case "feb":
    $data="content here";
    break;
    case "mar":
    $data="content here";
    break;
    case "apr":
    $data="content here";
    break;
    case "jun":
    $data="content here";
    break;
    case "jul":
    $data="content here";
    break;
    case "aug":
    $data="content here";
    break;
    etc...
    }
    

     

    Yeah, I forgot those. That is correct.

     

    Just as a reminder, there's a "Topic Solved" button below the thread on the left. Click that once you find a solution.

  11. How would I got about using mod_rewrite to rewrite:

     

    www.domain.com/index.php?home to www.domain.com/home

     

    but also have

     

    www.domain.com/index.php?profile=user_name to www.domain.com/username

     

    I guess I should be clear about this part:

     

    www.domain.com/index.php?profile=user_name to www.domain.com/username

     

    That should be a variable $user_name, would be rewritten to the same value of the variable.

     

    So:

     

    www.domain.com/index.php?profile=John would be rewritten to www.domain.com/John

     

    Could I just order them in order of importance, like this:

     

    RewriteRule ^/?([a-zA-Z0-9-]+)(?:/(.*))?$ index.php?$1
    RewriteRule ^/?([a-zA-Z0-9-]+)(?:/(.*))?$ index.php?profile=$1
    

     

    So things like /home would be caught first and see that value is in the php file. And when something isn't caught it would go to the next rewrite rule. I guess one issue is I have an else statement in the php file, so it will also return that, as opposed to going to the rewrite rule.

  12. You should not have a bunch of different files that only differ in the content they contain. You should have one file, then use the power of the php server side scripting language to dynamically get or produce the correct content within that one file. This will mean that your displayed output will be consistent and easier to maintain or alter. To change the layout, you only have one place that needs changing and to add or change the content, you simply add or change the data that defines the content.

     

    Must be too old, I do not know what you mean. I use the include in the index.php page. Usually a swf file that changes due to season. Would you explain what you meant in a different context and then I may understand.

    I still don't know about including images.

     

     

    Instead of having multiple pages you can do one page with something like this in it:

     

    switched_content.php

    $month=$_GET['month'];
    $month=strtolower($month); //Only necessary if switch statement cases are case sensitive - not sure
    switch ($month)
    case "jan":
    $data="content here";
    break;
    case "feb":
    $data="content here";
    break;
    case "mar":
    $data="content here";
    break;
    case "apr":
    $data="content here";
    break;
    case "jun":
    $data="content here";
    break;
    case "jul":
    $data="content here";
    break;
    case "aug":
    $data="content here";
    break;
    etc...
    

     

    Then on the page you want to include the item in:

     

    $_GET['month']=date("M");
    include 'switched_content.php';
    echo $data;
    

     

    This would pull the data inside the switch statement for the case of the current month. You could also condense it down to one file, but two files in my opinion is the way to go, keeps the bulk of the code out of the display file.

  13. $pages = array("jan.php", "feb.php", "mar.php", "apr.php", "may.php", "jun.php", "jul.php", "aug.php", "sep.php", "oct.php", "nov.php", "dec.php");
    $month = date("m");
    include($pages[$month - 1]);
    

     

    Probably overkill now. Just giving you another option.

     

    More consolidated:

    $pages = array("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
    $month = date("m");
    include "$pages[$month - 1]".'.php';
    

     

    But:

     

    Here's a slightly different slant on the problem.

     

    You should not have a bunch of different files that only differ in the content they contain. You should have one file, then use the power of the php server side scripting language to dynamically get or produce the correct content within that one file. This will mean that your displayed output will be consistent and easier to maintain or alter. To change the layout, you only have one place that needs changing and to add or change the content, you simply add or change the data that defines the content.

     

    Agree 100%.

  14. I just went with a function:

     

    Works with no issues.

    function menu($menu_array, $select = null){
    	$array=$menu_array;
    //Get Text for Links from Keys of Array
    	$menu_text = array_keys($array);
    
    	// produce and output the correct menu
    	$i=0;
    	$newmenu="";
    		if(isset($select) && $select!=null){
    		$newmenu.="<select>";
    		$menu_type="select";
    		}
    		else{
    		$menu_type="links";
    		}
    		foreach(array_values($array) as $link_option){
    			if($menu_type=="links"){
    			$newmenu.='<a href="'.$link_option.'">';
    			$newmenu.=$menu_text[$i];
    			$newmenu.='</a> ';
    			}
    			elseif($menu_type=="select"){
    			$newmenu.='<option value="'.$link_option.'" >'.$menu_text[$i].'</option>'."\n";		
    			}
    		$i++;
    		}
    		if(isset($select) && $select!=null){
    		$newmenu.="</select>";
    		}
    return $newmenu;
    }
    

  15. Your code is very scattered, and pretty much gibberish.

     

    1. You never declare $menu_array before using it.

     

    2. You have $i for no reason, and don't do anything with it after incrementing it.

     

    3. You use array_values for no reason, and never use $link_option in that loop (your other methods won't be able to 'see'/use $link_option due to scope).

     

    4. You try appending $this->menu to $this->newmenu when $this->menu has no value.

     

    ---

     

    Right now, it looks like you're panicking because the code isn't working right, and you're making random incremental changes hoping that somehow it'll fix the problem(s).  Your first three posts - written in the span of 30 minutes - highlight this.  You need to stop, take a deep breath, and really run through what you've already written.  None of it currently makes any kind of sense.  Do it with pen and paper, and map out the process.  Then, compare what you want to happen with what your current code is doing.

     

    What I'm trying to do is keep a majority of the code that is the same in __construct, then pull in the formatting/display structuring via generateTopMenu and generateSearchMenu, through $this->menu, then have the foreach statement and $i increment through the array pulled in via the __construct, applying the result (on $this->menu) to $this->new_menu, then return via the returnMenu function.

     

    I guess I can't do it that way? Otherwise if it can't work that way, then I have no point in doing it.

  16. Still not displaying anything. I used print_r on $this->menu_array and it did print out the array, it's just not running it through the foreach statement.

    class menu{
    
            private $newmenu;
            private $menu;
    public function __construct($array=array(), $index, $select = null){
    
    $this->menu_array=$array;
    
    	//Get Text for Links from Keys of Array
    	$menu_text = array_keys($this->menu_array);
    
    	// produce and output the correct menu
    	$i=0;
    		if(isset($select) && $select!=null){
    		$this->newmenu="<select>"; 
    		}
    		foreach(array_values($this->menu_array) as $link_option){
    		$this->newmenu.=$this->menu;
    		$i++;
    		}
    		if(isset($select) && $select!=null){
    		$this->newmenu.="</select>"; 
    		}
    }
    
    public function generateTopMenu(){
    $this->menu='<a href="'.$link_option.'">';
    $this->menu.=$menu_text[$i];
    $this->menu.='</a> ';
    }
    
    public function generateSearchMenu(){
    $this->menu.='<option value="'.$link_option[$i].'" >'.$menu_text.'</option>'."\n";
    }
    
    public function returnMenu(){
    return $this->newmenu;
    }
    }
    

  17. Just to bring things up to date again, I'm now trying this:

     

    class menu{
    public function __construct($menu_array, $index, $select = null){
    
    	//Get Text for Links from Keys of Array
    	$menu_text = array_keys($this->menu_array);
    
    	// produce and output the correct menu
    	$i=0;
    		if(isset($select) && $select!=null){
    		$this->newmenu="<select>"; 
    		}
    		foreach(array_values($this->menu_array) as $link_option){
    		$this->newmenu.=$this->menu;
    		$i++;
    		}
    		if(isset($select) && $select!=null){
    		$this->newmenu.="</select>"; 
    		}
    }
    
    public function generateTopMenu(){
    $this->menu='<a href="'.$link_option.'">';
    $this->menu.=$menu_text[$i];
    $this->menu.='</a> ';
    }
    
    public function generateSearchMenu(){
    $this->menu.='<option value="'.$search_text[$i].'" >'.$search_item.'</option>'."\n";
    }
    
    public function returnMenu(){
    return $this->newmenu;
    }
    
    
    }
    

     

     

    //Generate menu array
    $menu_array = array();
    $menu_array['loggedin'] = array("Home" => "/home","News Feed" => "/newsfeed","Notifications" => "/notifications","Requests" => "/requests", "Messages" => "/messages");
    $menu_array['loggedout'] = array("Music" => "/music","Movies" => "/movies","Television" => "/television","Games" => "/games", "Videos" => "/videos", "Browse People" => "/people");
    
    // logic to determine which menu to use
    if(isset($_SESSION['username'])){ $type = 'loggedin'; } 
    else { $type = 'loggedout'; }
    
    $toplinks = new menu($menu_array[$type], $type);
    $toplinks->generateTopMenu();
    echo $toplinks->returnMenu();
    

     

    Error notices are back:

     

    Warning: array_keys() expects parameter 1 to be array, null given in /homepages/27/d418565624/htdocs/class.php on line 103

     

    Warning: array_values() expects parameter 1 to be array, null given in /homepages/27/d418565624/htdocs/class.php on line 110

     

    Warning: Invalid argument supplied for foreach() in /homepages/27/d418565624/htdocs/class.php on line 110

     

    Seems as though the array isn't being passed as an array.

×
×
  • 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.