Jump to content

HDFilmMaker2112

Members
  • Posts

    547
  • Joined

  • Last visited

    Never

Everything posted by HDFilmMaker2112

  1. I'm really ready to just abandon this whole mod_rewrite thing. Everything worked fine until I tried to rewrite URLs.
  2. Also, to add to my last post. When I log-in with valid credentials it goes to the right page, but when I click on any of the links in the links bar, it logs me out.
  3. 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.
  4. 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 }
  5. 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.
  6. And when it changes (and it will, I'm on a development server with a different root then what the production site will be on), then I have to go back and change 100s of urls?
  7. 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]
  8. 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: ./"); } ?>
  9. 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]
  10. RewriteRule ^([A-Za-z0-9_]+)/?([A-Za-z0-9_]+)?/?$ /index.php?p=$1&edit=$2 Would the above match anything between a-Z and 0-9 with an optional / and an optional second "folder" with an optional /.
  11. And don't forget escape "$_POST['academy']" prior to running the query.
  12. ?? 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;"; ?>
  13. <?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.
  14. 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'; ?>
  15. 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.
  16. 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.
  17. 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
  18. 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.
  19. 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: Agree 100%.
  20. 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; }
  21. 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.
  22. 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; } }
  23. 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.