Jump to content

alphanumetrix

Members
  • Posts

    167
  • Joined

  • Last visited

Everything posted by alphanumetrix

  1. You'll need an authentication cookie of some sort for this to work properly. Otherwise, there's no way to distinguish the users. Without a way of distinguishing the users, this can't be done. I can briefly describe how to create and destroy cookies: /* creating a cookie - set's $_COOKIE['username'] for 1 hour. The value will be the user's username, but in the example below is just "Peron's Username Here" */ setcookie ("username", "Person's Username Here", time() + 3600, "/", "yoursite.com", 1); /* destroying a cookie - simply set the time to be less than the time allowed */ setcookie ("username", "Person's Username Here", time() - 3600, "/", "yoursite.com", 1); See here for more info: http://us2.php.net/setcookie I recommend you do some reading. It is a pain at first, but there's really not that much, and you'll learn a lot. Also, see sessions: http://us2.php.net/manual/en/ref.session.php Sessions you should learn to, as if used right, they can make your site more secure.
  2. How do you store your user authentication? Do you have a cookie/session already that has the user's ID, or no? If you don't have one already, how is it setup? Typically, I'll set a cookie to have the user ID in it, then I just query the cookie up for something like this. If don't though, you'll need to get whatever data from your user's field that is stored in your sessions/cookies. IE: if you're storing their usrename in a cookie. Then just create a query before the insert query to get the user's ID. IE: $results = array(); $sql = "SELECT * FROM users WHERE id = '".$_COOKIE['userid']."'"; $query = mysql_query($sql, $dblink) or die ('Error: ' . mysql_error() ); while ( $row = mysql_fetch_array($query, MYSQL_ASSOC)) array_push($results, $row); if ( count($results) == 1 ) $owner = $results[0][id]; else die ("Error: Either that username doesn't exist, or there were multiple people using the same username"); Could be a lot simple though. I need to know how your authentication is setup. IE: stored values of sessions/cookies
  3. Yeah, varcahr 255 probably would 'suffice'. However, make sure your image URL's don't exceed 255 characters. If they do, it won't work. Maybe instead of varchar, you should go with full_text.
  4. Just set it to primary or index. Don't make it autoincrement. I didn't say that, did I? For the posts that already exist, you will have to manually put the user ID's into the owner field (or write a script that does it for you). For all new posts though, you just need to remember that you have to record the user id in the 'owner' field every time they're submitted. Are you getting that error on the same script? We're not submitting any data right now. You're just trying to view it on this script.
  5. heliophobia? are you a vampire? wow... there are a lot of different people on here. guess I'll share, too. I'm Danny, just turned 15. I spend a fair amount of free time coding. Have no idea why at this point, just obsessed I guess. Other than that, I spend a lot of time at the movies and school...
  6. type this line in somewhere in your function, global $proposalid; - then just use your variable as you would. This is not prefered as you are using OOP, but should work, nevertheless.
  7. Do you have to be specific age to take the test? Can someone young take it, too?
  8. My mistake. I should have wrote owner in the WHERE clause, not blogID. Also, be sure that you have actually created the owner field, before testing. Fixed: $owner = $_GET['blog']; include "connect.php"; mysql_select_db("post_db") or die ("Could not select database because ".mysql_error()); $data = mysql_query("SELECT * FROM textpost WHERE owner = '" . $owner . "' ORDER BY date desc limit 10") or die(mysql_error()); echo "<h3>"."Your recent blog post's"."<br/>"."</h3>"; echo "<table align='right'>"; echo "<tr>"; echo "<td>"; echo "Login Page <a href='loginpage.html'>Click Here.</a>"; echo "</td>"; echo "<tr>"."<td> <br> </td>"."</tr>"; echo "<td>"; echo " Add New Post Here <a href='http://localhost/Project/add_post.php'>Click Here.</a>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "<table border='0' >"; while($info = mysql_fetch_array( $data )) { echo "<tr>"."<td><b>Title:</b></td> <td>".$info['title'] . "</td>"."</tr>"; echo "<tr>"."<td><b>Comment:</b></td> <td>".$info['comment'] . " </td>"."</tr>"; echo "<tr>"."<td><b>Authorname:</b></td> <td>".$info['authorname'] . " </td>"."</tr>"; echo "<tr>"."<td><b>Date:</b></td> <td>".$info['date'] . " </td>"."</tr>"; echo "<tr>"."<td> <br> </td>"."</tr>"; } echo "</table>"; ?>
  9. Okay, that looks pretty good. (didn't really evaluate it, but in essence, good). Now, since you already have a table for posts "textposts" - Add a field to that. Call it "owner" or something. Everytime a user creates a post, add their blog ID to the "owner" field of the post. This way, each post will be marked by that user (*they 'own' it now ). Then, just change your code slightly to recognize your blogs, based on the User's ID. An example of the URL would be: mysite.com/index.php?blog=1 (The blog=1 represents the ID of the user who 'owns' the blog). The code for this would be simple: $owner = $_GET['blog']; include "connect.php"; mysql_select_db("post_db") or die ("Could not select database because ".mysql_error()); $data = mysql_query("SELECT * FROM textpost WHERE blogID = '" . $owner . "' ORDER BY date desc limit 10") or die(mysql_error()); echo "<h3>"."Your recent blog post's"."<br/>"."</h3>"; echo "<table align='right'>"; echo "<tr>"; echo "<td>"; echo "Login Page <a href='loginpage.html'>Click Here.</a>"; echo "</td>"; echo "<tr>"."<td> <br> </td>"."</tr>"; echo "<td>"; echo " Add New Post Here <a href='http://localhost/Project/add_post.php'>Click Here.</a>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "<table border='0' >"; while($info = mysql_fetch_array( $data )) { echo "<tr>"."<td><b>Title:</b></td> <td>".$info['title'] . "</td>"."</tr>"; echo "<tr>"."<td><b>Comment:</b></td> <td>".$info['comment'] . " </td>"."</tr>"; echo "<tr>"."<td><b>Authorname:</b></td> <td>".$info['authorname'] . " </td>"."</tr>"; echo "<tr>"."<td><b>Date:</b></td> <td>".$info['date'] . " </td>"."</tr>"; echo "<tr>"."<td> <br> </td>"."</tr>"; } echo "</table>"; ?> Now it will only display posts owned by this user; everything else will be the same. How are you storing sessions/logs, btw? If you are using cookies/session, instead of using the index.php?blog=1 - you could just store a session/cookie with their user ID (if you don't have one already), and then have the site recognize it that way. Just by changing the one line of code I made - IE: $owner = $_COOKIE['userID']; Also, be sure to check for possible security errors with your scripts. Don't want anyone hacking it.
  10. Um... I don't think selected is supposed to be used in that way. I think it's supposed to be like: <option value="something" selected>Something</option> Try your function like this instead: function getYears($name, $startYear, $endYear, $tabIndex, $selected) { $year = $endYear; echo ("\n\n<select name=\"$name\" id=\"$name\" tabindex=\"$tabIndex\">\n"); if(empty($selected)){ echo("\n\t<option selected=\"selected\" value=\"\"></option>"); } while ($year >= $startYear) { if ($year == $selected) { echo("\n\t<option value=\"$year\" selected>$year</option>"); } else { echo("\n\t<option value=\"$year\">$year</option>"); } $year --; } echo ("\n</select>"); } Yes, because $year == $selected, it should be the same. However, == can mean equivalent values, too. So having said that, if $year = 0; & $selected = false; - I believe that would have the same translation. So instead of using this operator, perhaps try the identical comparison operator: === (just an extra =)
  11. He's right, str_replace() will work, but seeing as you're "not a coder," I'm guessing you wouldn't know how to intergrate that. This *should* work. <?php $CFG['db_host'] = 'localhost'; $CFG['db_user'] = 'USER'; $CFG['db_pass'] = 'PASSWORD'; $CFG['db_name'] = 'DB'; mysql_connect($CFG['db_host'], $CFG['db_user'], $CFG['db_pass']) or die(mysql_error()); mysql_select_db($CFG['db_name']); function tag_info() { $result = mysql_query("SELECT * FROM tags GROUP BY tag_name ORDER BY RAND() DESC LIMIT 40"); while($row = mysql_fetch_array($result)) { $arr[$row['tag_name']] = $row['count']; } //ksort($arr); return $arr; } function tag_cloud() { $min_size = 14; $max_size = 22; $tags = tag_info(); $minimum_count = min(array_values($tags)); $maximum_count = max(array_values($tags)); $spread = $maximum_count - $minimum_count; if($spread == 0) { $spread = 1; } $cloud_html = ''; $cloud_tags = array(); $step = ($max_size - $min_size)/($spread); foreach ($tags as $tag => $count) { $size = $min_size + ($count - $minimum_count) * $step; // $size = ($max_size + $min_size)/$spread; $theurl = htmlspecialchars(stripslashes($tag)); $theurl = str_replace(" ", "+", $theurl); $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" href="/search-' . $tag .'-blended' . '" title="' . $count . ' searches for \'' . $tag . '\'">' . $theurl . '</a>'; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; } ?> <?php if (!eregi('[.@\"\'!/:%]', $_GET['k'])) if (mysql_affected_rows()){ mysql_query("UPDATE tags SET count=count+1 WHERE tag_name=\"".$_GET["k"]."\""); } if (!mysql_affected_rows()){ mysql_query("INSERT INTO tags SET tag_name=\"".$_GET["k"]."\", count=1, search_date=NOW()"); } ?>
  12. you could always loop it. $highest = 1; foreach ($arr as $a) { if ( $highest <= $a ) $highest = $a; } echo $highest; edit -- didn't realize this was already solved...
  13. It's by computer from what I've read. And the questions are multiple choice, which can also have multiple answers. I heard by some people that it's pretty difficult, but the studyguide is said to be considerably overkill. All this is based on what I've heard/read, so don't take my word for it totally. I'd also like to hear what people have to say about this, especially if they actually have zend cert.
  14. um... i'm a little confused as to what you're looking for now? if you are trying to send the people to Yahoo, then just use the code i posted: header("location: http://www.yahoo.com");
  15. Aside from the e-mails likely being spam, it may not be sending e-mails because your server isn't allowing it. Many people can't use php's mail() function by itself. They have to use php's standard smtp class with it, as some servers require it.
  16. Try putting http:// before it. IE: header("location: http://yahoo.com"); Also, could you tell us where it's going, if that doesn't work? My guess, is it's going to a non-existent directory because you don't have http://
  17. Your cookie value was set to 0 anyway, so it would just be destroyed, I think.
  18. This should work: $fileurl = 'file url here'; $search = '<php require(include.php); ?>'; $replace = 'what you want there instead'; $file_contents = file_get_contents($fileurl); $fh = fopen($fileurl, "w"); $file_contents = str_replace($search,$replace,$file_contents); fwrite($fh, $file_contents); fclose($fh); To be sure not to overwrite something else, add some specific comment lines to the code. IE: <php require(include.php); /* special */ ?> - that way it's not the same as any other piece of code. Or you could also go by line, but I don't have a handy code ready for that.
  19. This should work, but may not depending on your particular situation. function getDays ($name, $tabIndex) { echo ("\n\n<select name=\"$name\" id=\"$name\" tabindex=\"$tabIndex\">\n <option selected=\"day\" value=\"\">"); $days = array ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"); if ($_POST[$name]) $extra = 'selected'; foreach ($days as $day) { echo("\n\t<option value=\"$day\" $extra>$day</option>"); } echo ("\n</select>"); }
  20. well, that code wouldn't work anyway. you declared $start outside of the function without making it global: $start = time(); function online($connection) { global $start; put this code at the top of your script: <?php $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; ;?> then put this where you want it: <?php $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); function online($connection) { global $totaltime; while(!$connection) { if($totaltime >= 2) { return false; break; } } return true; } if(online($connection)) { //Your server is online.. } else { //It's not } ;?>
  21. this should help get you started: $dir = 'my directory'; $handle = opendir($dir); $result = array(); while ( $listings = readdir($handle) ) { if ( $listings != '.' && $listings != '..' ) { if ( !preg_match("@^\d{6}.htm$@i", $filename) ) $result[] = $listings; } to display them: foreach ($result as $r) { echo '<li>' . $r . '</li>'; }
  22. My bad. You will have to use === for getting the boolean with strpos. So try this: $site = 'http://mysite.com'; foreach($html->find('a') as $e) { if ( strpos($e->href, $site) === true ) { echo $e->href . '<br>'; } }
×
×
  • 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.