Jump to content

Zola

Members
  • Posts

    72
  • Joined

  • Last visited

Everything posted by Zola

  1. Yep, absolutely understood. Ill give it a go. Many thanks
  2. Thanks for your replys. Thegate - i appreciate your reply, just got a query about it.. Wouldn't that mean i still have to manually update every page anyway? I like the idea though. Not sure how i would implement the array approach, mcgallforever
  3. I am relatively new to PHP, trying to learn more every day. I have been enjoying using Server Side Includes in my sidebars, footer etc with good results, much handier and more efficient! I would like to do the same for the header and main site navigation. However, the main problem that I am not sure how to deal with comes from having 'active' links (differently coloured menu tab for the page the user is on) in my menu. Here is a small menu example: <div class="menu"> <ul> <li><a href="nav.php" class="active">Home</a></li> <li><a href="nav2.php">About</a></li> <li><a href="products1.php">Products</a></li> <li><a href="products2.php">Products 2</a></li> <li><a href="products3.php">Products 3</a></li> </ul> </div> When the user is on the Home page, the class is set to active - i.e. a different colour. If I do a simple server side include with my navigation this will of course be across all the pages. Can anyone please advise on what I need to do to make the menu work correctly across all the pages? (have different tabs selected for each respective page). Any help / insight is much appreciated.
  4. rather embarrassingly, my doctype was the problem!! I downloaded the script and this way already there, didn't notice to change it. oops!
  5. Hi, I need to make a simple login section. I am using a small php script which holds the login information etc. The login form looks fine in Firefox, Chrome, Safari, but not in Internet Explorer. Does anyone know what is causing the form to go on the left side of the screen with no styling? Any help would be greatly appreciated. http://mgdesign.hostultra.com/login_/documents.php
  6. Hi, I am having issues getting a simple contact form getting past the junk filter and into the inbox. Is there something wrong with my code? I have tried to set the email to 'not junk' in the 2 different email providers, but not change. Here is my code: <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: Contact Form'; $to = 'my_email@gmail.com'; $subject = 'Hello'; $human = $_POST['human']; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; $headers .= "Content-type: text/plain; charset=utf-8\n"; $headers .= "From: website user<someone_from@mysite.com> \n"; if ($_POST['submit']) { if ($name != '' && $email != '') { if ($human == '10') { if (mail ($to, $subject, $body, $from)) { echo '<p>Your message has been sent!</p>'; } else { echo '<p>Something went wrong, go back and try again!</p>'; } } else if ($_POST['submit'] && $human != '4') { echo '<p>You answered the anti-spam question incorrectly!</p>'; } } else { echo '<p>You need to fill in all required fields!!</p>'; } } ?> <form method="post" action="mail_.php"> <label>Name</label> <input name="name" placeholder="Type Here"> <label>Email</label> <input name="email" type="email" placeholder="Type Here"> <label>Message</label> <textarea name="message" placeholder="Type Here"></textarea> <label>*What is 7+3? (Anti-spam)</label> <input name="human" placeholder="Type Here"> <input id="submit" name="submit" type="submit" value="Submit"> </form> Any help is greatly appreciated.
  7. I have a restricted page for members of a website. This restricted area is within a directory called 'download.' There is a login form on two pages (home and support pages, found in the main menu). These pages are on the site root directory. When the user successfully logs in they are taken inside the download directory to index.php. This index.php has a different look to the site root design. I have since redesigned this page to have the same structure as the site root pages. I would love for the user to able to navigate around the main site if they wanted, and when they clicked support in the menu they would have all the download files there on the page, instead of a login form. My question is how would I implement this login so that when the user logs in the support page changes from the login page to the page with the files. I don't want to to duplicate the site within the download directory, I was hoping for an efficient method, but I am unsure how to go about it.
  8. I updated it to this: $_SESSION['name'] = true; It now works. Thanks
  9. I thought that session_register("name"); and $_SESSION['name']; would be the same thing? I am new with PHP, please bear with me. What would I need to change it to?
  10. Hi, I am having difficulties with the login section on a website. I have tried to update the old funtion names which have been deprecated, but when I do this the login will not work. This is the log.php file, (this is required by index.php on the restricted directory to access the page). <?php session_start(); ?> <?php $hostname = ".."; $username = ".."; $password = ".."; $database = ".."; $link = MYSQL_CONNECT($hostname,$username,$password); mysql_select_db($database); ?> <?php if($_GET['action'] == "login") { $conn = mysql_connect("..","..","..); $db = mysql_select_db(".."); //Your database name goes in this field. $name = $_POST['user']; $ip=$_SERVER['REMOTE_ADDR']; $var = mysql_real_escape_string($var); $country = file_get_contents('http://stonito.com/script/geoip/?ip='.$ip); $q_user = mysql_query("SELECT * FROM customer WHERE username='$name'"); ?> <?php $insert_query = ("INSERT INTO login(username, ip, country) VALUES ('$name','$ip','$country');"); mysql_query($insert_query) or die('Error, insert query failed'); ?> <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { session_register("name"); header("Location: ../index.php?un=$name"); // This is the page that you want to open if the user successfully logs in to your website. exit; } else { header("Location: .."); exit; } } else { header("Location: .."); exit; } } // if the session is not registered if(session_is_registered("name") == false) { header("Location: login.php"); } ?> The two old code parts. causing the problems are session_register("name"); session_is_registered . When I change update elements in the code block shown below, it will not work. Can anyone tell me why please? <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { $_SESSION['name']; header("Location: ../download/index.php?un=$name"); // This is the page that you want to open if the user successfully logs in to your website. exit; } else { header("Location: .."); exit; } } else { header("Location: .."); exit; } } if(!isset($_SESSION['name'])) { header("Location: http://www.myurl.com"); } Any help would be very gratefully received.
  11. Hi, I am relatively new to PHP. This a login script for a restricted area on a website I am making. There is a database which collects info, such as who downloads what material, time stamps etc. This is log.php, a file which is required and called in index.php (within the restricted directory). This is a script I downloaded and modified for my own needs. I am hopeful someone would take a quick look at it and tell me if you see anything wrong, bugs, potential errors etc? Everything works fine, I am just interested in best practices. <?php session_start(); ?> <?php $hostname = ".."; $username = ".."; $password = ".."; $database = ".."; $link = MYSQL_CONNECT($hostname,$username,$password); mysql_select_db($database); ?> <?php if($_GET['action'] == "login") { $conn = mysql_connect("..","..",".."); $db = mysql_select_db(".."); //Your database name goes in this field. $name = $_POST['user']; $ip=$_SERVER['REMOTE_ADDR']; $var = mysql_real_escape_string($var); $country = file_get_contents('http://stonito.com/script/geoip/?ip='.$ip); $q_user = mysql_query("SELECT * FROM customer WHERE username='$name'"); ?> <?php $insert_query = ("INSERT INTO login(username, ip, country) VALUES ('$name','$ip','$country');"); mysql_query($insert_query) or die('Error, insert query failed'); ?> <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { $_SESSION["name"]; header("Location: http://myurl.com/restricted.php"); // This is the page that you want to open if the user successfully logs in to your website. exit; } else { header("Location: http://myurl.com/register.html"); exit; } } else { header("Location: http://myurl.com/"); exit; } } // if the session is not registered if(!isset($_SESSION['name'])) { header("Location: http://www.myurl.com"); } ?> Thanks for any input.
  12. // if the session is not registered if(session_is_registered("name") == false) { header("Location: http://www.myurl.com"); } ?> I have this at the bottom of my login script to redirect to the register page. What should I be writing instead?
  13. Sorry for the noob questions, but I am learning all about this stuff. Thanks very much
  14. I found this code, can someone explain it a little to me please? <?php $random_text = array("Random Text 1", "Random Text 2", "Random Text 3", "Random Text 4", "Random Text 5"); $sizeof = count($random_text); $random = (rand()%$sizeof); print("$random_text[$random]"); ?> Why do we need the $sizeof and count?
  15. Hi, I am wanting to create a random fact script for a small website project. The idea is when the user loads a page a random fact will appear at the top ( I guess from an array of strings I will make?) Can anyone recommend the most efficient and easiest way to go about this please?
  16. Update! This has been fixed now! I had two duplicate files which were conflicting - one (an older log.php file) in the root directory and one in the restricted directory. They were causing the whole problem. I = noob, but at least I am learning. I also swatted up on books and videos and removed lots of garbage code that wasn't needed.
  17. Thanks! I will take your points in and will hopefully get this sorted.
  18. Hi mate, thanks for the reply, I appreciate it!! I have added the statements here: $name = $_POST['user']; $var = mysql_real_escape_string($var); $ip=$_SERVER['REMOTE_ADDR']; $var = mysql_real_escape_string($var); I am very new to PHP and MySQL. can you explain what this does and a little about the potential threat please? I am eager to learn. The login problem for some users will be when they try to log in from the index page. When they submit the form seems to post the data, but then the page refreshes on the index page. Its just like someone pressed refresh in the browser. Then when they submit data again it will work.
  19. Hi, I have a restricted area for my work's company. This is an area where registered users with their own user name and password can access to download technical documents etc. I am hearing some reports that users will have to login twice to get to the area - This happens in Chrome, IE 7/8 and some Firefox's. It has only happened to me once or twice. Does anyone know why this may be? Here is the HTML code from the login form on the index page: <form name="login_form" method="post" action="log.php?action=login"> <p>Login:<br /> <input type="text" name="user" /> </p> <p>Password: <br /><input type="password" name="pwd" /> </p> <p class="submit"> <input type="submit" value="Submit" name="submit" class="submit" /> </p> </form> Here is the log.php File: (personal connection details edited) <?php $hostname = "IP:3306"; $username = "user"; $password = "password"; $database = "db_name"; $link = MYSQL_CONNECT($hostname,$username,$password); mysql_select_db($database); ?> <?php session_name("MyWebsiteLogin"); session_start(); if($_GET['action'] == "login") { $conn = mysql_connect("IP:3306","user","password"); $db = mysql_select_db("db_name"); //Your database name goes in this field. $name = $_POST['user']; $ip=$_SERVER['REMOTE_ADDR']; $country = file_get_contents('http://api.hostip.info/country.php?ip='.$ip); $q_user = mysql_query("SELECT * FROM customer WHERE username='$name'"); ?> <?php $insert_query = ("INSERT INTO login(username, ip, country) VALUES ('$name','$ip','$country');"); mysql_query($insert_query) or die('Error, insert query failed'); ?> <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { session_register("name"); header("Location: http://#/download/index.php?un=$name"); // This is the page that you want to open if the user successfully logs in to your website. exit; } else { header("Location: login.php?login=failed&cause=".urlencode('Wrong Password')); exit; } } else { header("Location: login.php?login=failed&cause=".urlencode('Invalid User')); exit; } } ?> Any help or ideas would be greatly appreciated.
  20. Hi, I am new here and I really hope to learn lots and become a good PHP programmer. I am a web and print designer so understand HTML/CSS etc, but I am not proficient in PHP at all. I have recently purchased "Learning PHP" by David Sklar (O'Reilly books).
×
×
  • 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.