-
Posts
188 -
Joined
-
Last visited
Posts posted by mdmartiny
-
-
Hello everyone,
I am working on site and I would like some feedback on it.
To login into the members area username is DemoDude and the password is password.
Critique and suggestions will be greatly appreciated.
Michael
-
I put session _start in it.. and it worked out.... Thought that since I had it in my init.php file I did not have to add it again. Guess I was wrong.
Thank You
-
In my init file I have session_start()...
-
I am trying to add a captcha to a registration form that I all ready have made.
I keep getting told that the captcha in the image and the characters that I am entering do not match. I am hoping that an extra set of eyes will help me find the problem.
This is the registration page
"<?php include('function/init.php'); ?> <!doctype html> <?php include('includes/head.php'); ?> <body> <div class="gridContainer clearfix"> <?php include('includes/header.php'); ?> <div id="register"> <?php if(!empty($_POST['human_check'])) { $filtered_email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL); if (user_exsits($_POST['username']) === true) { $errors[] = "The username <em>" . $_POST['username'] . "</em> is already taken"; } if (preg_match("/\\s/", $_POST['username']) == true) { $errors[] = "your username can not contain any spaces"; } if (strlen($_POST['password']) < 6 && !empty($_POST['password'])) { $errors[] = "Password must be longer than 6 characters"; } if ($filtered_email === FALSE && !empty($_POST['email'])) { $errors[] = "<em>".$_POST['email']."</em> is not a valid email"; } else { if (email_exsits($filtered_email) === true) { $errors[] = "The email <strong>'" . $_POST['email'] . "'</strong> is already in use"; } } if($_POST['human_check'] != $_SESSION['is_human']){ $errors[] = "Captcha was wrong please try again!"; } if (empty($_POST) === false && empty($errors) === true) { $register_data = array( 'username' => $_POST['username'], 'password' => $_POST['password'], 'name' => $_POST['name'], 'email' => $_POST['email'], ); register_user($register_data); header('Location: register.php?success'); exit(); } else if (empty($errors) === false) { echo output_errors($errors); } } else if (isset($_GET['success'])) { echo "<div class='reg-success'>You have successfully registered!</div>"; echo "<br /><br />"; echo "<form action='index.php' method='post' name='login'> <ul> <li> Username<br /> <input ID='user' TYPE='text' NAME='user' required autocomplete='off' /></li> <li>Password<br /> <input ID='pass' TYPE='password' NAME='pass' required autocomplete='off' /></li> <li><input id='submit-log' type='submit' name='submit-log' value='log in' /></li> </ul> </form>"; } ?> <h1 class="header">Register</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <ul> <li> Name<br /> <input ID="user" TYPE="text" NAME="name" required /></li> <li> E-mail<br /> <input ID="user" TYPE="text" NAME="email" required /></li> <li> Username<br /> <input ID="user" TYPE="text" NAME="username" required /></li> <li>Password<br /> <input ID="user" TYPE="password" NAME="password" required /></li> <li id='captcha_part'> <span class="explain">Click on captcha to refresh image</span> <img id ="captcha" src="captcha.php" onclick="javascript:reloadCaptcha()"> </li> <li>Captcha<br /> <input id="user" type='text' name='human_check' required placeholder='Enter captcha characters'> </li> <li><input id="submit" type="submit" name="register" value="Register" /></li> </ul> </form> </div> <?php include('includes/footer.php'); ?> </div> </body> <script language="javascript" type="text/javascript"> function reloadCaptcha(){ document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date(); } </script> </html>"
This is the captcha page
"<?php ///////////Editable Variables/////////// $image_width = 220; //sets image's width $image_height = 80; //sets image's height $red = rand(0,255); //random colors for lines $green = rand(0,255); $blue = rand(0,255); $red1 = rand(100, 200); //random colors for lines $green1 = rand(90, 190); $blue1 = rand(80, 180); $min_font_size = 20; $max_font_size = 25; ///////////May not want to edit below this section/////////// $human = ""; for($x = 0; $x < 2; $x++){ $human .= chr(rand(48,57)); } for($x = 0; $x < 3; $x++){ $human .= chr(rand(65,90)); } for($x = 0; $x < 2; $x++){ $human .= chr(rand(97,122)); } $_SESSION['is_human'] = $human; $image = imagecreate($image_width, $image_height); //creates image $background = imagecolorallocate($image, 255, 255, 255); //sets background color $text_color = imagecolorallocate($image, $red, $green, $blue); //sets text color $angle = rand(0,15); $fonts = array('appleberry_with_cyrillic.ttf', 'BlackCastleMF.ttf','DennisHillSpeeding.ttf','Diskoteque.ttf','the beautiful ones.ttf'); //sets an array of fonts $font = rand(0, 4); // generates a random number to used to load a font $font_path = "css/fonts/"; $human_text = $_SESSION['is_human']; // sets variable captcha_text = to the session called captcha for($i=0; $i<75; $i++) { // for loop to generate random lines and line colors for captcha background $x1 = rand(0, 220); $y1 = rand(0, 220); $x2 = rand(0, 220); $y2 = rand(0, 220); $line_color = imagecolorallocate($image, $red1, $green1, $blue1); //sets line color imageline($image, $x1, $y1, $x2, $y2, $line_color); //creates a line } imagettftext($image, rand($min_font_size, $max_font_size), $angle, 40, 70, $text_color, $font_path.$fonts[$font], $human_text); //creates captcha text header("Content-type: image/jpeg"); imagejpeg($image); //makes the image imagedestroy($image); //to save ram ?>"
Would appreciate it if someone could help me or point me in the right direction
-
Sorry it has been a couple of days since I have responded.
The company that hosted my site has had their database system down for two days with no explanation. So I had to wait for them to get it back up and I switched providers. I did that like an hour ago and after I switched the shortner has been working.
This is my final code if you were wondering
RewriteEngine On # Do not remove this line, otherwise mod_rewrite rules will stop working RewriteBase / ErrorDocument 404 /error/404.php ErrorDocument 500 /error/500.php # First, the stuff I don't want # Only shortit.zxq.net and shortit.org are acceptable hostnames RewriteCond %{HTTP_HOST} !^(shortit.zxq.net|shortit.org)$ RewriteRule ^ http://shortit.org%{REQUEST_URI} [L,R=301] # Don't allow people to go to /index.php?code=xyz and send them to /xyz # I prefer looking at the exact request for things like this RewriteCond %{REQUEST_URI} ^/index\.php\?code=([a-zA-Z0-9]+)$ RewriteRule ^ index.php? [L] # Now stuff I do want # Non-existant requests like /xyz are shortcodes RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?([a-zA-Z0-9]+)$ index.php?code=$1 [L]
Thank you for all of your assistance in helping me figure this out
-
I am sorry if I confused everyone.
I am not getting any error messages. It is not putting out any at least from what I can see.
When I try to use a URL that has been shortened it takes me to a 404 error page... It does not redirect based on the URL like I am trying to get it to do. Once again I am sorry if I have confused people.
-
It is just not redirecting like I want it to. I am not really getting errors on it.
-
I am still getting errors from it... I will play with it some more later. :-\
Is working with htaccess pages really this difficult?
-
Where is your source code? I do not see it.
Nevermind I found the attachment. If that is the code that you are using then it will allow for multiple entries in the database. In order to prevent that from happening you need to have an auto incremented field. That will give you an unique field that will allow not allow duplicated entries.
-
On a site that I am working on I have several different CSS files. I have some that are general css files and more that are specified to certain pages of the site. I use a function that I had written to switch out the more specified css files based on the name of the page
-
RewriteEngine On ErrorDocument 404 /error/404.php ErrorDocument 500 /error/500.php # First, the stuff I don't want # Only shortit.zxq.net and shortit.org are acceptable hostnames RewriteCond %{HTTP_HOST} !^(shortit.zxq.net|shortit.org)$ RewriteRule ^ http://shortit.org%{REQUEST_URI} [L,R=301] # Don't allow people to go to /index.php?code=xyz and send them to /xyz # I prefer looking at the exact request for things like this RewriteCond %{REQUEST_URI} ^/index\.php\?code=([a-zA-Z0-9]+)$ RewriteRule ^ index.php? [L] # Now stuff I do want # Non-existant requests like /xyz are shortcodes RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z0-9]+)$ index.php?code=$1 [L]
-
I just re did the htacess page and it is still not working. I made the changes that you suggested.
The only one that works now is the link that writes out the whole code along with the query string
When I type in shortit.zxq.net/index.php?code=OV8R6t takes me through the redirect
When I type in shortit.zxq.net/OV8R6t gives me an 404 error
when I type in shortit.org/OV8R6t all it does is take me to http://shortit.org/index.php
-
That is what I thought might of been happening after I had read the last post.
The strip query part was supposed to remove the query string so that user information was not posted in the url. Like on the view-links.php page. So people did not see view-links.php?u=1. I guess that is not really important. Just thought it would look nicer.
Thank you for your help. I will definitely do more research on htacess pages.
-
Where did it take you? The page associated with the code? Or the index page of the url shortner?
How would I write the htaccess page for both domains? This is my first time using htacess.
-
OK I did some playing around with the site and this is what I came up with... I am not sure why it is doing this. So I am hoping that someone can explain it to me
When I type in shortit.zxq.net/index.php?code=OV8R6t or shortit.zxq.net/OV8R6t it works
but when I type in shortit.org/OV8R6t all it does is take me to the index page of the site?
So what I am taking from it is that the code works so there has to be something with the URL
-
Hello everyone,
Here is what I am working on. I am in the process of creating a URL shortner. I am only doing this so that i can learn more about PHP. The problem that I am having is that the shortened URl keeps redirecting back to the home page instead of the site that it is supposed to represent.
Example: http://shortit.org/IlwU3g
I typed in the full url like this http://shortit.org/index.php?code=$IlwU3g
Here is the code for my htaccess page
RewriteEngine On RewriteBase / RewriteRule ^([a-zA-Z0-9]+)$ index.php?code=$1 ##### Remove query string ################################### RewriteCond %{QUERY_STRING} . RewriteRule ^(.*)$ [url="http://shortit.org/$1"]http://shortit.org/$1[/url]? [R=301,L]
Here is the function I am using to do the redirect
function redirect($code){ $code = mysql_real_escape_string($code); if(code_exists($code)){ $url_query = mysql_query("SELECT `url` FROM `urls` WHERE `code` = '$code'") or die (mysql_error()); $url = mysql_result($url_query, 0 , 'url'); header('Location:' . $url); } }
Here is the code from my index page
<?php include('function/init.php'); if(isset($_GET['code']) && !empty($_GET['code'])) { $code = $_GET['code']; redirect($code); die(); } ?> <!doctype html> <!--[if gt IE 8]><!--><html class=""> <!--<![endif]--> <base href="http://shortit.org"> <?php include('includes/head.php'); ?> <script src="/js/respond.min.js"></script> <script TYPE="text/javascript" SRC="/js/jquery.js"></script> <script TYPE="text/javascript"> function go(url){ $.post('/url.php', { url:url }, function(data) { if(data == 'error_no_url') { $('#message').html('<p>No Url Specified</p>'); }else if (data == 'error_invalid_url') { $('#message').html('<p>Not a Valid URL</p>'); } else if (data == 'all_ready_short') { $('#message').html('<p>Allready a shortit.org URL</p>'); }else { $('#url').val(data); $('#url').select(); $('#message').html('<p>Sucessfully Shortened your URL!</p>'); } }); } </script> <body> <div class="gridContainer clearfix"> <?php include('includes/header.php'); ?> <div id="LayoutDiv1"> <h1>Shorten your URL</h1> <ul> <li><input ID="url" TYPE="text" NAME="url" SIZE ="60" placeholder="http://" autofocus onkeydown="if(event.keyCode == 13 || event.which == 13) { go($('#url').val()); }" /></li> <li><input ID="submit" TYPE="submit" NAME="shorten" VALUE="shorten url" onclick="go($('#url').val());" /></li> </ul> <div ID="message"> <p> </p> </div> <div class="columns"> <div class="col-1"> <p class="col-header">Future Additions</p> <p>Share links on Facebook one click</p> <p>Share links on twitter one click</p> <p>Share links on google+ one click</p> <p>Custom URL's</p> <p>Ability to give names to your most used links</p> <p>Ability to track your URL's</p> <p>Tell your friend about system</p> </div> <div class="col-2"> <p class="col-header">Links</p> <?php $random_url = mysql_query("SELECT * FROM `urls` ORDER BY RAND() LIMIT 0,1;"); $random = mysql_fetch_array($random_url, MYSQL_ASSOC); echo "<p><a href='http://".$random['url']."' target='new'>Random Shortit URL</a></p>"; ?> <p>Most common URL shortened(coming soon)</p> <p>Most clicked URL(coming soon)</p> </div> <div class="col-3"> <p class="col-header">Statistics</p> <p><?php echo url_count(); ?> URL's currently in database</p> </div> </div> </div> <?php include('includes/rightside.php'); include('includes/footer.php'); ?> </div> </body> </html>
-
I have a shortner website that I am working on. Just a little project that I am doing in hopes that i can learn better.
Anyways my issue is that the shortened links are not working like they should. Actually they are not working at all. I keep getting a 404 page.
When I do something like shortit.org/123456 I get the 404 page.
shortit.org is the site that I am working on.
Here is the redirect code
<?php include('function/init.php'); if(isset($_GET['code']) && !empty($_GET['code'])) { $code = $_GET['code']; redirect($code); die(); } ?>
here is the redirect function
function redirect($code){ $code = mysql_real_escape_string($code); if(code_exists($code)){ $url_query = mysql_query("SELECT `url` FROM `urls` WHERE `code` = '$code'") or die (mysql_error()); $url = mysql_result($url_query, 0 , 'url'); header('Location:' . $url); } }
here is my .htaccess
RewriteEngine on RewriteRule ^([a-zA-Z0-9]+)$ index.php?code=$1
-
Here is the link... Select the trucks table and you will see what I am talking about
-
I have tried every solution that I could find by Googling and nothing seemed to work. Could some please help me
Here is my CSS
h1 { font-size:1.8em; } h2 { font-size:1.4em; } .logo { font:2em Arial; margin:0 0 10px 0; padding:0; width:200px; color:#fff; } /* Containers */ body { background:lightslategray; font-family:Arial; font-size:0.8em; } #container, footer { background:#fff; max-width: 75%; margin:0 auto; } #main { width: 75%; float: left; padding-left: 25px; height: 100%; min-height:100%; } header { max-width:75%; padding:10px; margin:0 auto 10px auto; } #container { min-height:500px; position: relative; padding-top: 100px; padding-bottom: 50px; border-radius:5px 5px 0 0; } .widget { margin-bottom:20px; } .widget h2 { margin:0 0 10px 0; padding:0 5px; font-weight:normal; border-bottom:1px solid #ddd; } .widget .inner { margin:0 10px; } /* Navigation */ nav { float:left; } nav ul { margin:0; } nav ul li { display:inline; margin-right:10px; } nav ul li a { text-decoration:none; } nav ul li.current { font-weight:bold; } nav ul li a.last { border-right:0; } /* Aside */ aside { width:260px; border-left:1px dashed #aaa; padding-left:15px; min-height: 99.4%; position: absolute; top: 10px; right: 10px; } /* Login */ #login li.link { margin-top:5px; } /* Footer */ footer { border-top:1px dashed #ddd; color:#999; text-align: center; border-radius:0 0 5px 5px; padding-top: 10px; } footer ul { margin-bottom: 15px; width: 80%; margin-right: auto; margin-left: auto; } footer ul li{ margin-right: 5px; display: inline-block; width: auto; font-size: 9px; line-height: 10px; height: 10px; } footer ul li a{ color: lightslategray; text-decoration: none; } footer ul li a:hover { text-decoration: underline; } /* Misc */ .clear { clear:both; }
here is the code that I am working with
<?php include ('includes/core/init.php'); //protect_page(); include ('includes/head.php'); ?> <!DOCTYPE html> <html> <body> <?php include('includes/header.php'); ?> <div ID="container"> <?php include('includes/aside.php'); ?> <div id="main"> <?php if(empty($_GET)) { include('includes/table/edit.php'); } else if(isset($_GET['list'])) { include('includes/table/listtable.php'); } else if($_GET['delete']){ include('includes/table/delete.php'); } else if(isset($_GET['modify'])){ include('includes/table/modify.php'); } ?> </div> </div> <?php include('includes/footer.php'); ?> </body> </html>
The problem lies in the main div. the information placed inside of it goes over top of the div.
-
I figured out what the problem was... I had the field length in the table set to 20. Once I changed it to the 32 characters that md5 does it worked.
-
Hello everyone,
I am writing some code for a login script. I keep getting the error Resource ID #13. What does this mean and how can I fix it?
Here is the code that I am having trouble with
function user_id_from_username($username) { $username = sanitize($username); $query = mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"); return mysql_result($query, 0, 'user_id'); } function login($username, $password) { $user_id = user_id_from_username($username); $username = sanitize($username); $password = md5($password); $query = "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"; return (mysql_result(mysql_query($query), 0) == 1) ? $user_id : false; }
-
Hello everyone,
I am writing some code for a login script. I keep getting the error Resource ID #13. What does this mean and how can I fix it?
Here is the code that I am having trouble with
function user_id_from_username($username) { $username = sanitize($username); $query = mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"); return mysql_result($query, 0, 'user_id'); } function login($username, $password) { $user_id = user_id_from_username($username); $username = sanitize($username); $password = md5($password); $query = "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"; return (mysql_result(mysql_query($query), 0) == 1) ? $user_id : false; }
-
I have a dynamic form that I am writing a script for to allow people to modify the fields of the form. I am taking all of the information that they have entered into the post array.
Where I am having a problem is that it is not showing all of the fields in the post array. One of the fields is an image field and the name of the image does not show up in the array when I do print_r or anything.
One other thing that I would like to know is how to get rid of the submit key and value from the array. I have tried using the unset method but it still shows up in the array.
<?php session_start(); include ('includes/connection.php'); connect(); $table = $_GET['table']; $id = $_GET['id']; $errors = array(); $mod_sql = "SELECT * FROM $table WHERE id = '$id'"; $mod_sql_result = mysql_query($mod_sql); $info = mysql_fetch_assoc($mod_sql_result); $mod_form = "<form name='insert_table' id='insert_table' action='" . $_SERVER['PHP_SELF'] . "?id=$id&table=$table' method='post' enctype='multipart/form-data'> <fieldset> <legend>table information</legend> <input TYPE='hidden' VALUE='" . $table . "' />"; foreach ($info as $key => $val) { $header = str_replace("_", " ", $key); if ($key == 'id') { $mod_form .= "<p>" . $header . ": <input name='" . $key . "' id='" . $key . "' type='text' value='" . $val . "' readonly='readonly' /></p>"; } else if ($key == 'image') { $mod_form .= "<p>Current image: <img style='vertical-align: text-top;' src='../db_images/ad_images/" . $val . "' /><input type='checkbox' name='delete_image' id='delete_image' value='" . $val . "' />Delete this image?</p> <p>" . $header . ": <input name='" . $key . "' id='" . $key . "' type='file' /></p>"; } else { $mod_form .= "<p>" . $header . ": <input name='" . $key . "' id='" . $key . "' type='text' value='" . $val . "' /></p>"; } } $mod_form .= " <p> <input type='submit' name='submit_mod' id='submit_mod' /> </p> </fieldset> </form> "; echo $mod_form; if (isset($_POST['submit_mod'])) { $table = $_POST['table']; $allowed_ext = array('jpg', 'jpeg', 'png', 'gif'); $file_name = $_FILES['image']['name']; $file_ext = (explode(".", $file_name)); $file_ext = strtolower(end($file_ext)); $file_size = $_FILES['image']['size']; $file_tmp = $_FILES['image']['tmp_name']; if (isset($_POST['delete_image'])) { $delete_image_name = $_POST['delete_image']; unlink('../db_images/ad_images/' . $delete_image_name); } if ($file_name != " ") { $new_image = $file_name; move_uploaded_file($file_tmp, '../db_images/ad_images/' . $file_name); } // This is the section of code that I am having trouble with foreach ($_POST as $key => $value) { if ($key == 'image') { $value = $new_image; } $insert_query = "UPDATE $table SET `$key` = '$value' WHERE id = $id"; $insert_action = mysql_query($insert_query); } echo $insert_query; } if (mysql_error()) { $error = "<strong>MySQL error</strong>:<br />" . mysql_errno() . ": " . mysql_error() . "\n<br>When executing:<br>\n$insert_query\n<br>"; $page = $_SERVER["REQUEST_URI"]; $log = "INSERT INTO db_error (`error_id`, `error_page`,`error_text`,`query`) VALUES ('','$page','" . mysql_real_escape_string($error) . "','" . mysql_real_escape_string($mod_sql) . "')"; $insert_log = mysql_query($log); echo $error; if ($insert_log) { echo "<p>Error has been added to the error log</p><p>The error id number is " . mysql_insert_id() . ""; } else { echo "Error adding to error log<br />" . mysql_errno() . ": " . mysql_error(); } } ?>
-
Thank you for all of the help... I have been reading about the unset function to remove things from an array but when I do
unset($info[0])
it does not remove the item from my view
Could You Give Me A Review Of A Site That I Am Working On
in Website Critique
Posted
I ask for that stuff because I am trying to get input about how people browse and if there is any issue with certain browsers stuff like that.
Where were the 404 errors?
I will work on the links and try to make it easier for them to be read.
Why the page went blank I have no idea.. I just tried and it worked fine for me.
Thank you for your feedback and your input.