PHP - Different Logins For Different Directories - One Landing Page
sorry you guys, but another question here from a mildly-talented PHP user..... I started designing a website for someone with wordpress, however like all 3rd party apps, it's very limited in what it can do when a need arises that is complex in nature, which is what I have. I'm using GoDaddy as a hosting company and their cPanel tool can't do this, so I must use PHP or something similar to get it done. Here's what I've got: => I have many dirs and subdirs on my site. the reason for this is to partition/separate out many files that cover a wide variety of topics. so the addresses look kind of like this:
> www.domain.com/content/software/ms-office/ms-access What I would like to do, because the site won't be available to the general public for a few months yet, is give people who want to know what the site is about a preview of what they will see in 3 months. But these people always have only one discipline/focus for their job. So I'd like to let them look at the content on the site that is only relevant to their expertise (for instance, like above, the "ms-access" dir), because I can't be showing them the other free resources offered by the site owner, especially if the owner brings in revenue for his business using that knowledge. So in the above example, how could I use PHP/MYSQL to issue separate usernames and passwords for 2 different people => 1 that wants to look at ms access content (they would only have access to "ms-office/ms-access" and "advanced/code-samples"), and 1 that wants to look at visual studio content ("ms-dot-net/visual-studio")?? Ideally what I'd like to do is only have to issue one password *per* software category dir, and have that password work for any other nested dirs lower than that. So in the above example, giving credentials for access would allow the user to view any page on, or nested below the dir "ms-access". If they try to view any file in any other dir, regardless of whether it is higher or lower on the directory tree, I want to block them. Can this be done? GoDaddy's tool can't do it. It would also be nice if I could issue a universal redirect to a landing page/login page as the result given to a user that tries to access any given page on this website for the first time, if they typed in a literal URL instead of going to the homepage. I hope you guys can help me figure this out, or maybe point me to some good internet resources where I can learn how to do it myself. thanks! (by the way, I know I can use PHP/MYSQL to produce dynamic pages with query strings, but I just chose this method to make it easier for the next developer to follow, because they're not that intellectual) Similar TutorialsI'm trying to build a landing page with php & js validation - i create the html/php & etc, but the .JS script always hangs on the last "else"... and gives the "123" alert... i debugged it for syntax problem for hundred of time with any online debugging site i know - but it's seems to be something else.... Hello- I want to create is fairly simple client login. Basically we have an area in our server, a directory really, filled with pw protected directories which house client project sites, basically viewing rooms for graphics and video we post. we have a few sites up and working, but instead of giving our clients a link and a password (which is kinda sloppy) it would be ideal to have them go to a single index page and login from there. I see the client entering a name and password and the script would match it to the directory and they would be taken to their designated client area. Another way would be to select their directory from a drop down and then enter the user and password, though then clients will be able to see other clients names, which would be less than ideal for disclosure reasons. I hope this makes sense. I am not new to html css, but have only a bit of experience with php, so any help would be greatly appreciated. thanks Matt Basically I have 2 log ins. The first one is for computer browsers, and the other is for iPad users. The normal one is called "index.php", and is located on the root folder of the server, the other is located in a directory called "Mobile2" and is also called "index.php". They are exactly the same page. I took the site that I had built and copy and pasted it into that directory and changed the css to fit better on the iPad. My problem is that now the log in does not work on the root sites log in, but doe on the iPad version in the new directory. any thoughts as to why this would happen ? Hi I have this code and when I echo the count it shows 1 when theres actually 5. Have I wrote it wrong $loginsq = mysql_query("SELECT email FROM logindetails WHERE email = ".$_SESSION['MM_Username'].""); $logins = mysql_fetch_array($loginsq); $logs = count($logins); echo $logs; ............. else if(empty($password)){ $errorMsg[]="please enter password"; } else { try { $select_stmt=$db->prepare("SELECT * FROM tbl_user WHERE username=:uname OR email=:uemail"); $select_stmt->execute(array(':uname'=>$username, ':uemail'=>$email)); $row=$select_stmt->fetch(PDO::FETCH_ASSOC); if($select_stmt->rowCount() > 0) { if($username==$row["username"] OR $email==$row["email"]) { if(password_verify($password, $row["password"])) { $_SESSION["user_login"] = $row["user_id"]; //---------------- $pdo_statement=$db->prepare("update tbl_user set logins=7 where user_id=2"); $result = $pdo_statement->execute(); //---------------- $loginMsg = "Successfully Login..."; header("refresh:2; welcome.php"); } else hey guys iam starting to learn during this crysis php :-). I got stucked with this pdo style..... i like to count logins, i tryed and figured out i can use the id... but my question is how can replace this "where user_id=2" to get the specific ID for the current user login in? the count function i i know how to make the... first i want to know how to write the syntax of this pdo...... thank you :-) I am about to attempt to write my first php script from scratch after a year or so of copying and adapting code. I am going to do a registration/login in system and thinking ahead, want to make sure that once someone is logged in, this information is passed from page to page (so they do not have to log in again on each page) and I would also like to provide a 'Remember Me' option. I have had a read up and from what I gather, sessions would be better for showing someone is logged in from page to page and cookies would be the only way to implement a 'Remember Me'. Would this be the best way to approach this or is/are there better ways? Thanks in advance Steve Hey guys, Im trying to combine 2 logs to seperate parts of a website into 1. One of them uses sessions to store it. And the other uses cookies to login. I cant seem to get it working AT ALL. Even tho the cookies are being set and I can see it being set in firefox. Here is the page with the sessions. <?php if(isset($_POST['username'])){ $username = $_POST['username']; //name of the text field for usernames $password = $_POST['password']; //likewise here just for the password //connect to the db $user = 'root'; $pswd = ''; $db = 'chat'; $conn = mysql_connect('localhost', $user, $pswd); mysql_select_db($db, $conn); //run the query to search for the username and password the match $query = "SELECT * FROM users WHERE username = '$username' AND password ='$password'"; $result = mysql_query($query) or die("Unable to verify user because : " . mysql_error()); //this is where the actual verification happens if(mysql_num_rows($result) == 1){ //the username and password match //so e set the session to true session_start(); $_SESSION['username'] = $username; //STUFF FROM HERE TO THE OTHER COMMENT IS STUFF I ADDED MANUALLY TRYING TO GET THE COOKIES TO BE SET SO THEY WORK FOR BOTH $username = $_COOKIE['user_id']; $pass = $_COOKIE['pass_id']; setcookie("user_id", "$username", time()+3600); setcookie("pass_id", "$pass", time()+3600); //END OF THE CUSTOM STUFF, IT DOESNT WORK FOR SOME REASON //and then move them to the index page or the page to which they need to go header('Location: index.php'); }else{ $err = 'Incorrect username / password.' ; } //then just above your login form or where ever you want the error to be displayed you just put in echo $err; } else ?> I made comments // in the code so you can see whats going on. Here is the code that uses cookies, also it uses 2 pages. This is the one I think that mainly adds the cookies. <?php // Login Logic $username = ""; $err = ""; $err_style = ""; $err_style2= ""; //Checks if there is a login cookie if(isset($_COOKIE['user_id'])) { //if there is, it logs you in and directes you to the members page $username = $_COOKIE['user_id']; $pass = $_COOKIE['pass_id']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());$quer++; while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: index.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // SANITISE $username = sanitize($_POST['username']); $pass = sanitize($_POST['pass']); $red = sanitize($_POST['red']); // makes sure they filled it in if(!$_POST['username']) { $err = 'You did not fill in a required section'; $err_style = "style='border: 1px solid #CC0000'"; $show_login = 1; } if(!$_POST['pass']) { $err = 'You did not fill in a required section'; $err_style2 = "style='border: 1px solid #CC0000'"; $show_login = 1; } // checks it against the database if (!$err) { $check = mysql_query("SELECT * FROM users WHERE username = '".$username."'")or die(mysql_error());$quer++; //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { $err = 'User not found - please try again!'; $err_style = "style='border: 1px solid #CC0000'"; $show_login = 1; } while($info = mysql_fetch_array( $check )) { $info['password'] = stripslashes($info['password']); $pass = $pass; //gives error if the password is wrong if ($pass != $info['password']) { $err = 'Incorrect password, please try again.'; $err_style2= "style='border: 1px solid #B02B2C;'"; $show_login = 1; } else { // if login is ok then we add a cookie $hour = time() + 3600; setcookie("user_id", $username, $hour); setcookie("pass_id", $pass, $hour); //then redirect them to the members area if (!$red) { header("Location: index.php"); } else { header("Location: $red.php"); } exit; } } } } ?> Here is the other page it also includes inside. <?php Check.php session_start(); //checks cookies to make sure they are logged in if(isset($_COOKIE['user_id'])) { $username = $_COOKIE['user_id']; $pass = $_COOKIE['pass_id']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());$quer++; while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //otherwise they are shown the admin area else { // Update some info setcookie ("user_id", $_COOKIE['user_id'], time() + 3600 ); setcookie ("pass_id", $_COOKIE['pass_id'], time() + 3600 ); // Get some basic user details, so we can use these later! $uname = $info['username']; $uID = $info['user_id']; $loggedin = 1; $admin_user = $info['admin']; } } } ?> Thanks for the upcoming help that you all provide. If anything else is needed please post here and il provide it. Hey guys does anyone know of a good dynamic directory solution? What i mean by this is when i am creating an application and i use require_once 'includes/config.php'; and then i create a class that needs the config file so i include it into the class like so: require_once '../include/config.php'; then i make a new folder named member then i have to require this class (created above) and it fails to find the directory. What would be a good solution for this? Thanks guys!! So I have a simple template that I want to be the index page of the website that I'm working on, however, I don't want to have to create several almost identical files for each of the directories.
Is there perhaps anyway that I can change the content of the main div yet the address be a different directory.
So for example, this is the main index page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head> <title>Matthew Noskiw's website - Home</title> <link rel='stylesheet' type='text/css' href='./inc/CSS/styles/default.css' /> <link rel='stylesheet' type='text/css' href='./inc/CSS/static/navigation.css' /> </head> <body> <div id='Container'> <div id='Header'> <div class='right'> <ul id='Navigation'> <li id='NavButton' class='active'><a href='./'>Home</a></li> <li id='NavButton'><a href='./about'>About</a></li> <li id='NavButton'><a href='./blog'>Blog</a></li> <li id='NavButton'><a href='./contact'>Contact</a></li> </ul> </div> <span>noskiw.co.uk</span> </div> <hr /> <div id='MainContent'> <h2>Home</h2> <br /> <span> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </span> <br /><br /> <span> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? </span> </div> <hr /> <div id='Footer'> <span>Matthew Noskiw</span> </div> </div> </body> </html>But if you look in the <h2> tag in the 'MainContent' div, then you'll see it reads "Home". What I want to happen is that when I change the page, for example, go to /about I want it to read <h2>About</h2>. I have 4 different pages for this so far, is there any way to get it down to just one yet they be in different directories? P.S The reason this is in the PHP Help section is because I assumed that it would more than likely be something to do with PHP. Edited by ghostrider1337, 02 August 2014 - 02:36 PM. I am using the following code: Code: [Select] <?php $target = "images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?> I am using this to upload photos to the directory called 'images'. How could I change this code so that I can choose an existing directory to upload it to and also create a new directory to upload it to if I wanted? I am a php newb. I have 2 somewhat simple problems. First I have a huge list of movies that I would like sorted in a drop down list alphabetically. I already have the drop down list made and the movies show up correctly. But I cannot figure out how to sort the list. Here is the code <?php $dir="/backup/Movies"; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php") { $thelist .= '<option>'.$file.'</option>'; } } closedir($handle); } ?> <form action="listen.php" method="post" name="table"> <select name="Movie"> <P><?=$thelist?></p>' </select> </form> Second problem is inside this directory there are a few other directories is it possible to make the directories show at the top instead of them being sorted alphabetically with the movies. Thanks in advance Jake i need to convert the following path Code: [Select] $url=http://www.test.com/images/1/7/4/7/9/thumb.jpg to Code: [Select] $updated_url= /home/vhosts/test.com/httpdocs/images/1/7/4/7/9/thumb.jpgThe directories in the url are created dynamically Right now what i am doin is Code: [Select] $updated_url='/home/vhosts/'.$url.'/httpdocs/images/'.basename($url)which gives me /home/vhosts/test.com/httpdocs/images/thumb. But I also need to get the directories 1/7/4/7/9. It may be differ for different urls. Can this be done through some form of string replacement or pattern matching method? I have one input upload and need it to go to two directories here is my upload code that handles the move_upload_file portion. Code: [Select] move_uploaded_file($_FILES['fillPDF']['tmp_name'], $strNewsPath . $strFilename); Thanks in advance. Hello everyone, This is a fairly simple question, but the explanation of the question isn't... I'll do my best. I have a site where my folders/sub-folders/files are arranged similar to this: _ Root Folder -| Root-IncludeFile1.php | Root-IncludeFile2.php | _ | Sub-Folder 1 -| Sub1-File1.php | |_Sub1-File2.php | _ | Sub-Folder 2 -| Sub2-File1.php | |_Sub2-File2.php | _ |_Sub-Folder 3 -| Sub3-IncludeFile1.php |_Sub3-IncludeFile2.php Hopefully that makes sense to everyone. Anyway, I know that to include a file that is in the root folder in file in a sub-folder, I can do this - include("../includefile1.php"); -but I'm trying to include a file that is in a sub folder in a file that is in another sub-folder. For example, I'm trying to include "Sub3-IncludeFile1.php" in "Sub-File1.php" I'm lost on this because I can't get it to work. I'm not getting any error messages except to say that the variables located in the file that should be included are not found. I've tried to do this: include("http://www.mysite.com/Sub-Folder3/Sub3-IncludeFile1.php"); and it doesn't work. Can someone please point me in the right direction? Thanks in advance for your help. I have written a piece of code that create a directories, files on the server using mkdir and touch and also inserts the form data into the table.. the code gets executed and the info gets stored in the database but the part which has the create directories. and files dont work as it doesnt create the directory and files on the server.. do i need to make changes to the php.ini file to enable the mkdir and touch feature to get enabled? as i said the code executes without any error.. I dont know wat to do.. please any help would be appreciated!! thanku How do I include a file that is located two directories above the file that I want to include the file into? My absolute hosting path is /home/content/52/8840652/html if this would be of any use. I'm not quite sure about the PHP include functions. Any help would be greatly appreciated, Thanks! This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=347966.0 Here is my code which i use to recieve uploaded files.
$filepath = $_SERVER['DOCUMENT_ROOT'] . "file/"; $fileunzippath = $filepath."unzipped/"; $exclude_list = array(".", "..", "...", "index.php", ".php", ".htaccess"); if($_FILES["zip_file"]["name"]) { $filename = $_FILES["zip_file"]["name"]; $source = $_FILES["zip_file"]["tmp_name"]; $type = $_FILES["zip_file"]["type"]; $name = explode(".", $filename); $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed'); foreach($accepted_types as $mime_type) { if($mime_type == $type) { $okay = true; break; } } $continue = strtolower($name[1]) == 'zip' ? true : false; if(!$continue) { $message = "The file you are trying to upload is not a .zip file. Please try again."; } $string = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $filename); $clean_name = strtr($string, array('Š' => 'S','Ž' => 'Z','š' => 's','ž' => 'z','Ÿ' => 'Y','À' => 'A','Á' => 'A','Â' => 'A','Ã' => 'A','Ä' => 'A','Å' => 'A','Ç' => 'C','È' => 'E','É' => 'E','Ê' => 'E','Ë' => 'E','Ì' => 'I','Í' => 'I','Î' => 'I','Ï' => 'I','Ñ' => 'N','Ò' => 'O','Ó' => 'O','Ô' => 'O','Õ' => 'O','Ö' => 'O','Ø' => 'O','Ù' => 'U','Ú' => 'U','Û' => 'U','Ü' => 'U','Ý' => 'Y','à' => 'a','á' => 'a','â' => 'a','ã' => 'a','ä' => 'a','å' => 'a','ç' => 'c','è' => 'e','é' => 'e','ê' => 'e','ë' => 'e','ì' => 'i','í' => 'i','î' => 'i','ï' => 'i','ñ' => 'n','ò' => 'o','ó' => 'o','ô' => 'o','õ' => 'o','ö' => 'o','ø' => 'o','ù' => 'u','ú' => 'u','û' => 'u','ü' => 'u','ý' => 'y','ÿ' => 'y')); $clean_name = strtr($clean_name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); $clean_name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $clean_name); $target_path = $filepath.$clean_name; // change this to the correct site path if(move_uploaded_file($source, $target_path)) { echo "Source: ".$source."<br/>"; echo "Type: ".$type."<br/>"; echo "Filename: ".$filename."<br/>"; $zip = new ZipArchive(); $x = $zip->open($target_path); if ($x === true) { $zip->extractTo($fileunzippath.$clean_name); // change this to the correct site path $zip->close(); $exclude_list; $dir_path = $_SERVER['DOCUMENT_ROOT']; $dir_path .= "/file/unzipped/"; $directories = array_diff(scandir($fileunzippath.$clean_name), $exclude_list); foreach($directories as $entry) { if(is_dir($dir_path.$entry)) { if($entry != 'part0' || $entry !='part1') { rmdir($entry); } } } } $message = "Your .zip file was uploaded and unpacked."; } else { $message = "There was a problem with the upload. Please try again."; } }Specifically i want to highlight this part: $exclude_list; $dir_path = $_SERVER['DOCUMENT_ROOT']; $dir_path .= "/file/unzipped/"; $directories = array_diff(scandir($fileunzippath.$clean_name), $exclude_list); foreach($directories as $entry) { if(is_dir($dir_path.$entry)) { if($entry != 'part0' || $entry !='part1') { rmdir($entry); } } }When I upload a zip file containing 2 directories(one called 'part0', and one called 'bad'), they get unzipped correctly and it gives no errors, however the fake directories(not called part0 or part1) I put in there are still there. Any Help? This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=321151.0 |