Jump to content

Jurge

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Everything posted by Jurge

  1. I figured a way out in the end was actually pretty simple. Thanks for everyone's comments.
  2. ah I see so there's no simple answer?
  3. I currently have a flat file user registration and login in system. I also have a simple guestbook which i didn't code myself, the guest book currently requires the user to type in there name and e-mail address to make a post. how ever i would like them to have to login and if they aren't logged in then don't display the guestbook. Live version: B50crew.co.uk Guestbook.php: <?php // find out the domain: $domain = $_SERVER['HTTP_HOST']; // find out the path to the current file: $path = $_SERVER['SCRIPT_NAME']; $url = "http://" . $domain . $path ; extract($_POST); if($Submit){ $date = date('D d Y h:i'); $comment=eregi_replace("\r\n","*",$comment); $comment=eregi_replace("\n","*",$comment); $fp = fopen("bin/guestbook.nfo","a+"); if(!$fp) { echo 'Error: Cannot open file.'; exit; } fwrite($fp, $date."||".$name."||".$email."||".$comment."\n"); fclose($fp); } ?> <div align="center"> <h2><span class="style1">Guestbook </span><br> </h2> </div> <form name="form1" method="post" action="<?php echo $url;?>"> <label>Name <input type="text" name="name"> </label> <label>Email <input type="text" name="email"> </label> <p> </p> <p> comment<br> <textarea name="comment" cols="40" rows="10"></textarea> <br> <label> <input type="submit" name="Submit" value="Sign"> </label> <br> </p> </form> <hr> <?php $userinfo = file("cgi-bin/guestbook.nfo"); echo '<table border="0">'; foreach($userinfo as $val) { //explode that data into a new array: $data = explode("||", $val); echo '<tr><td>'.$data[0].'</td></tr>'; echo '<tr><td>'.$data[1].' Wrote:</td></tr>'; $data[3]=eregi_replace("\*","<br>",$data[3]); echo '<tr><td>'.$data[3].'</td></tr>'; echo '<tr><td>Email:'.$data[2].'<hr></td></tr>'; } echo '</table>'; ?> Login: <?php // find out the domain: $domain = $_SERVER['HTTP_HOST']; // find out the path to the current file: $path = $_SERVER['SCRIPT_NAME']; $url = "http://" . $domain . $path ; extract($_POST); if($Submit){ $date = date('D d Y h:i'); $comment=eregi_replace("\r\n","*",$comment); $comment=eregi_replace("\n","*",$comment); $fp = fopen("bin/guestbook.nfo","a+"); if(!$fp) { echo 'Error: Cannot open file.'; exit; } fwrite($fp, $date."||".$name."||".$email."||".$comment."\n"); fclose($fp); } ?> <div align="center"> <h2><span class="style1">Guestbook </span><br> </h2> </div> <form name="form1" method="post" action="<?php echo $url;?>"> <label>Name <input type="text" name="name"> </label> <label>Email <input type="text" name="email"> </label> <p> </p> <p> comment<br> <textarea name="comment" cols="40" rows="10"></textarea> <br> <label> <input type="submit" name="Submit" value="Sign"> </label> <br> </p> </form> <hr> <?php $userinfo = file("cgi-bin/guestbook.nfo"); echo '<table border="0">'; foreach($userinfo as $val) { //explode that data into a new array: $data = explode("||", $val); echo '<tr><td>'.$data[0].'</td></tr>'; echo '<tr><td>'.$data[1].' Wrote:</td></tr>'; $data[3]=eregi_replace("\*","<br>",$data[3]); echo '<tr><td>'.$data[3].'</td></tr>'; echo '<tr><td>Email:'.$data[2].'<hr></td></tr>'; } echo '</table>'; ?> Session.php <?php class user { var $file_dir = ""; function start($time = 3600) { session_set_cookie_params($time , ''); session_name('afroxav-login'); session_start(); // Reset the expiration time upon page load if (isset($_COOKIE['afroxav-login'])) { setcookie('afroxav-login', $_COOKIE['afroxav-login'], time() + $time, '', 'localhost', 0, 1); } if (!isset($_SESSION['info'])) { $this->data = array('name' => 'Anonymous', 'logged' => false); } else { $this->data = $_SESSION['info']; } } function check_login() { if ($this->data['logged'] !== true) { return false; } else if ($this->data['logged'] === true) { if ($this->data['name'] !== 'Anonymous') { return true; } return false; } return false; } function login($user, $pass) { $logins_raw = @file_get_contents($this->file_dir . 'users.php'); $logins_processed = str_replace('<?php exit; ?>', '', $logins_raw); $logins_array = explode('\n', $logins_processed); foreach ($logins_array as $id => $line) { $logins[$id] = explode('|', $line); } $pass = $this->hash_pass($pass); foreach ($logins as $user_info) { if ($user_info[1] == $user) { if ($user_info[2] == $pass) { $this->update_session($user_info); return true; } } } return false; } function hash_pass($string) { return hash('sha512', $string); } function logout() { $_SESSION['info'] = array('name' => 'Anonymous', 'logged' => false); $this->data = $_SESSION['info']; return true; } function prep_reg_array($name, $pass, $email, $mod = 'false', $admin = 'false') { $id_raw = @file_get_contents($this->file_dir . 'id.php'); $id = str_replace('<?php exit; ?>', '', $id_raw); $id = $id + 1; @file_put_contents($this->file_dir . 'id.php', '<?php exit; ?>' . $id); return array($id, $name, $this->hash_pass($pass), $email, $mod, $admin); } function register($userdata) { $write = file_put_contents($this->file_dir . 'users.php', '\n' . implode('|', $userdata), FILE_APPEND); return ($write !== false) ? true : false; } function update_session($array) { $_SESSION['info'] = array( 'id' => $array[0], 'name' => $array[1], 'pass' => $array[2], 'email' => $array[3], 'mod' => $array[4], 'admin' => $array[5], 'logged' => true ); $this->data = $_SESSION['info']; } }; //html related functions //not related at all with the sessions function html_start($title) { header('Content-type: text/html'); echo "<html>\n"; echo "<head>\n"; echo "<title>\n"; echo $title; echo "</title>\n"; echo "</head>\n"; echo "<body>\n"; echo "<h1>\n"; echo $title; echo "</h1>\n"; } function html_nav() { global $user; echo "<div>\n"; echo "Navigation\n"; echo "<ul>\n"; echo "<li><a href=\"?page=home\">Home</a></li>\n"; if ($user->check_login() == true) { echo "<li><a href=\"?page=logout\">Log Out</a></li>\n"; } else { echo "<li><a href=\"?page=login\">Log In</a></li>\n"; echo "<li><a href=\"?page=register\">Register</a></li>\n"; } echo "</ul>\n"; echo "</div>\n"; } function html_end() { echo "</body>\n"; echo "</html>\n"; } ?>
  4. Pardon me, I've just read through it and realised i've not explained very well, let me try again. I have a flat file login system on my site, I also have a flat file guestbook. After the user has logged in i want the guestbook to be able to find the username and email address from the flat file login, and therefore when a user signs the guestbook with a comment, there username and email are displayed, as opposed to the current one which requires the user to type in the name and email. Thanks
  5. Login: <?php // find out the domain: $domain = $_SERVER['HTTP_HOST']; // find out the path to the current file: $path = $_SERVER['SCRIPT_NAME']; $url = "http://" . $domain . $path ; extract($_POST); if($Submit){ $date = date('D d Y h:i'); $comment=eregi_replace("\r\n","*",$comment); $comment=eregi_replace("\n","*",$comment); $fp = fopen("bin/guestbook.nfo","a+"); if(!$fp) { echo 'Error: Cannot open file.'; exit; } fwrite($fp, $date."||".$name."||".$email."||".$comment."\n"); fclose($fp); } ?> <div align="center"> <h2><span class="style1">Guestbook </span><br> </h2> </div> <form name="form1" method="post" action="<?php echo $url;?>"> <label>Name <input type="text" name="name"> </label> <label>Email <input type="text" name="email"> </label> <p> </p> <p> comment<br> <textarea name="comment" cols="40" rows="10"></textarea> <br> <label> <input type="submit" name="Submit" value="Sign"> </label> <br> </p> </form> <hr> <?php $userinfo = file("cgi-bin/guestbook.nfo"); echo '<table border="0">'; foreach($userinfo as $val) { //explode that data into a new array: $data = explode("||", $val); echo '<tr><td>'.$data[0].'</td></tr>'; echo '<tr><td>'.$data[1].' Wrote:</td></tr>'; $data[3]=eregi_replace("\*","<br>",$data[3]); echo '<tr><td>'.$data[3].'</td></tr>'; echo '<tr><td>Email:'.$data[2].'<hr></td></tr>'; } echo '</table>'; ?> Session: <?php class user { var $file_dir = ""; function start($time = 3600) { session_set_cookie_params($time , ''); session_name('afroxav-login'); session_start(); // Reset the expiration time upon page load if (isset($_COOKIE['afroxav-login'])) { setcookie('afroxav-login', $_COOKIE['afroxav-login'], time() + $time, '', 'localhost', 0, 1); } if (!isset($_SESSION['info'])) { $this->data = array('name' => 'Anonymous', 'logged' => false); } else { $this->data = $_SESSION['info']; } } function check_login() { if ($this->data['logged'] !== true) { return false; } else if ($this->data['logged'] === true) { if ($this->data['name'] !== 'Anonymous') { return true; } return false; } return false; } function login($user, $pass) { $logins_raw = @file_get_contents($this->file_dir . 'users.php'); $logins_processed = str_replace('<?php exit; ?>', '', $logins_raw); $logins_array = explode('\n', $logins_processed); foreach ($logins_array as $id => $line) { $logins[$id] = explode('|', $line); } $pass = $this->hash_pass($pass); foreach ($logins as $user_info) { if ($user_info[1] == $user) { if ($user_info[2] == $pass) { $this->update_session($user_info); return true; } } } return false; } function hash_pass($string) { return hash('sha512', $string); } function logout() { $_SESSION['info'] = array('name' => 'Anonymous', 'logged' => false); $this->data = $_SESSION['info']; return true; } function prep_reg_array($name, $pass, $email, $mod = 'false', $admin = 'false') { $id_raw = @file_get_contents($this->file_dir . 'id.php'); $id = str_replace('<?php exit; ?>', '', $id_raw); $id = $id + 1; @file_put_contents($this->file_dir . 'id.php', '<?php exit; ?>' . $id); return array($id, $name, $this->hash_pass($pass), $email, $mod, $admin); } function register($userdata) { $write = file_put_contents($this->file_dir . 'users.php', '\n' . implode('|', $userdata), FILE_APPEND); return ($write !== false) ? true : false; } function update_session($array) { $_SESSION['info'] = array( 'id' => $array[0], 'name' => $array[1], 'pass' => $array[2], 'email' => $array[3], 'mod' => $array[4], 'admin' => $array[5], 'logged' => true ); $this->data = $_SESSION['info']; } }; //html related functions //not related at all with the sessions function html_start($title) { header('Content-type: text/html'); echo "<html>\n"; echo "<head>\n"; echo "<title>\n"; echo $title; echo "</title>\n"; echo "</head>\n"; echo "<body>\n"; echo "<h1>\n"; echo $title; echo "</h1>\n"; } function html_nav() { global $user; echo "<div>\n"; echo "Navigation\n"; echo "<ul>\n"; echo "<li><a href=\"?page=home\">Home</a></li>\n"; if ($user->check_login() == true) { echo "<li><a href=\"?page=logout\">Log Out</a></li>\n"; } else { echo "<li><a href=\"?page=login\">Log In</a></li>\n"; echo "<li><a href=\"?page=register\">Register</a></li>\n"; } echo "</ul>\n"; echo "</div>\n"; } function html_end() { echo "</body>\n"; echo "</html>\n"; } ?> The user details are just stored in a file called users.php
  6. I am creating a guestbook for a friend who has access to a hosting server for free, however they are reluctant to let us create databases so i have used a flat file system to create a simple login and register system. On this site I have also included a flatfile guestbook, I've not coded this from scratch as I'm just not php freak enough for it. The guestbook requires a name and email address to submit a post, i would like to change this so that it takes the details straight from the flatfile and not be displayed at all if there is no-one logged in. Guestbook.php <?php // find out the domain: $domain = $_SERVER['HTTP_HOST']; // find out the path to the current file: $path = $_SERVER['SCRIPT_NAME']; $url = "http://" . $domain . $path ; extract($_POST); if($Submit){ $date = date('D d Y h:i'); $comment=eregi_replace("\r\n","*",$comment); $comment=eregi_replace("\n","*",$comment); $fp = fopen("bin/guestbook.nfo","a+"); if(!$fp) { echo 'Error: Cannot open file.'; exit; } fwrite($fp, $date."||".$name."||".$email."||".$comment."\n"); fclose($fp); } ?> <div align="center"> <h2><span class="style1">Guestbook </span><br> </h2> </div> <form name="form1" method="post" action="<?php echo $url;?>"> <label>Name <input type="text" name="name"> </label> <label>Email <input type="text" name="email"> </label> <p> </p> <p> comment<br> <textarea name="comment" cols="40" rows="10"></textarea> <br> <label> <input type="submit" name="Submit" value="Sign"> </label> <br> </p> </form> <hr> <?php $userinfo = file("cgi-bin/guestbook.nfo"); echo '<table border="0">'; foreach($userinfo as $val) { //explode that data into a new array: $data = explode("||", $val); echo '<tr><td>'.$data[0].'</td></tr>'; echo '<tr><td>'.$data[1].' Wrote:</td></tr>'; $data[3]=eregi_replace("\*","<br>",$data[3]); echo '<tr><td>'.$data[3].'</td></tr>'; echo '<tr><td>Email:'.$data[2].'<hr></td></tr>'; } echo '</table>'; ?>
  7. It shouldn't be that difficult I just don't know how to do it myself. I'm using the following code for a simple navigation, i has been placed in the content of my home page, it works fine however i don't know how to set the home page. <div id="content"> <?php $page = $_GET['page']; $file = $page.".php"; if(file_exists($file)) { include($file); } else { include "error.php"; } ?> </div>
  8. Thanks for the $_SERVER['REMOTE_ADDR'] and yeh, I have set up a database, but only for the admin section of the site.
  9. The first is more simple... well I think it probably is, I have made a form that sends the inputted information to my e-mail address but I would also like to be able to capture the users IP address and send the to my e-mail too. The second is a problem of i don't know where to start, so if some one could point me in the direction of a good tutorial I would be very grateful. I need to create a for and online radio so that the djs can book hour slots to dj in, but i don't just want a HTML table so that the dj's have to contact me i have to edit it and upload it, i want the dj's to be able to do it themselves.
  10. sounds like a good solution and the link seems like a good explanation. thanks.
  11. o_o; surely if you uploaded the files in the first place you have them in a local dir anyways?
  12. I have made a few developments to my site that alloow the site to be edited with php, however i ahve not been able to secure these files so technically anyone could use them. I have tried 3 different methods of protecting them but none of them have been quite what i was looking for does anyone have any ideas that can be achieved without the use of a database (I am too noob for database). The methods i have tried are: .htaccess and .htpasswd, but my free hosting service doesn't let em go above the root folder to add the .htpasswd file. <?php require_once('../login.php'); ?> at the top of all protected pages, this clashed with the scripts that I already had on the pages. and a pre-made php script for a login but you can bypass the login by going straight to the file so it's pointless for my needs. very grateful to anyone that can help thanks.
  13. I think site searches can be quite easy, i've only ever done simple ones. and Pm me if you need help with the graphics i will do it for free even if he is paying you.
  14. It looks like it's developing. The background took a while to load. and if i hadn't of taken a few seconds to think about how i could critique i might of missed it. although the background is nice, it's best to use a medium size image and repeat it. Perhaps if the blue in the layout was the same as the orange in the background they wouldn't look so vivid next to each other, but perhaps thats the look you were going for. hard to critique a personal site as all of our opinions make no difference because it's not our page.
  15. Nice work, The aesthetics need some work I think a nice banner would set it off nicely i could make you a nice one in seconds if you like? The layout is clean and tidy and the structure is good. perhaps if you have so many items a search feature might be necessary not many people like trawling through pages to find what they want.
  16. Okay first I have to apolagize because the solutions is probably very simple but I don't know my JS What i wanted to make is an image that changes every 5 seconds or so but each image has a different link. I used a code that looks like this to achieve the changing but i didn't know how to add links. Head <HEAD> <SCRIPT LANGUAGE="JavaScript"> var interval = 2.5; // delay between rotating images (in seconds) var random_display = 1; // 0 = no, 1 = yes interval *= 1000; var image_index = 0; image_list = new Array(); image_list[image_index++] = new imageItem("http://javascript.internet.com/img/image-cycler/01.jpg"); image_list[image_index++] = new imageItem("http://javascript.internet.com/img/image-cycler/02.jpg"); image_list[image_index++] = new imageItem("http://javascript.internet.com/img/image-cycler/03.jpg"); image_list[image_index++] = new imageItem("http://javascript.internet.com/img/image-cycler/04.jpg"); var number_of_image = image_list.length; function imageItem(image_location) { this.image_item = new Image(); this.image_item.src = image_location; } function get_ImageItemLocation(imageObj) { return(imageObj.image_item.src) } function generate(x, y) { var range = y - x + 1; return Math.floor(Math.random() * range) + x; } function getNextImage() { if (random_display) { image_index = generate(0, number_of_image-1); } else { image_index = (image_index+1) % number_of_image; } var new_image = get_ImageItemLocation(image_list[image_index]); return(new_image); } function rotateImage(place) { var new_image = getNextImage(); document[place].src = new_image; var recur_call = "rotateImage('"+place+"')"; setTimeout(recur_call, interval); } </script> </HEAD> [body] <BODY OnLoad="rotateImage('rImage')"> <center> <img name="rImage" src="http://javascript.internet.com/img/image-cycler/01.jpg" width=120 height=90> </center>
  17. shadiadiph is right you have told the cell in the table to take up 100% of the space it would be easier to do this with divs btw, just set it's width to inherit and sets it's max width to 350 in the css and it will change with out messing up.
  18. I can't be certain unless i have read the CCS but i would imagine: delete the code for 2 of the collums in the html then make the remain column 3 times bigger in the css.
  19. http://twabbo.net46.net/ here is a website i have made for a friend, there is a marquee by where it says "Dj Says" (which i had made red so that you can see it easily) I have made it using a php include like this <marquee><?php include('marquee.html') ?></marquee> This works fine in IE and safari. but not Mozilla. I'm not sure why so i reckoned it must be the html sorry if i have posted in the wrong area. also thought i should mention that i have used sepearte style sheets for mozilla and IE <link rel="stylesheet" type="text/css" href="style.css" /> <![if !IE]> <link rel="stylesheet" type="text/css" href="notie.css" /> <![endif]>
×
×
  • 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.