Jump to content

PHPiSean

Members
  • Posts

    79
  • Joined

  • Last visited

    Never

Everything posted by PHPiSean

  1. Thank you very much Sandeep. Is there a way I could use this for italics URL and bold tags now? Eg: #i# #b# and #url#? Thank you very much for your help by the way
  2. Thanks again for your help, I read the tutorial in your signature, but go confused right when they dove it. Oh well one of these days I'll take a step-by-step method towards regex.
  3. Actually it works brilliantly now! Thanks a ton! By the way, is there a way I could pack this all into a method? I would do it right-off-the-bat but I don't know about the idea of a function inside the function (the callback) The current code I have follows: <?php $stage1 = "This is the free version, here you are #code#<?php echo \"This is the code\"; echo \"<br/>\"; echo \"and some more code\"; ?>#/code# And yeah lol"; function callback($src) { return "<div class='stylearoundcode'><br/>".htmlentities($src[1]) ."</div><br/>" ; } $stage1= preg_replace_callback("/#code#(.*)#\/code#/sm",'callback',$stage1); $stage1 = stripcslashes($stage1); echo "<pre>"; echo $stage1; echo "</pre>"; ?> Thanks again Sandeep!
  4. Thanks for the reply from both of you. Sandeep, yours has the more desired result with the pound signs (sorry playful I edited my post right when after you viewed it). However, Sandeep's outputs nothing as for now. Moving on, I want to replace the area where the code tags were with <div class=stylearoundcode> and </div>. From the div name, I just want to give them a nice box around it so that it can be distinguished from the rest of the user's post. Also, is there a way I could use brackets such as [ and ] instead of greater than and less than signs? Much like this site does?
  5. Hello everyone, I am an absolute novice when it comes to regex. I could learn it it strongly, but I need to spend much more time than I have. I am stuck with a problem where regex becomes a requirement. In short, I need to use regex to change code submitted by users to divs and htmlentities the code. I commented on the code because explaining there would make much more sense than explaining here. Anyways, it's much like this forum with the code tags. In my code, I've changed the code tags to have pound signs around them just so SMF won't think I'm posting more code inside a code tag. I'm sure there's an escape method, but here's the code: <?php //code outputted from database, I need to regex the code so that #code# is replaced by divs and the code is passed through htmlentities() $stage1 = "This is the free version, here you are #code#<?php echo \"This is the code\"; echo \"<br/>\"; echo \"and some more code\"; ?>#/code#"; //regex //how it should look after the regex process $stage2 = "This is a free version, here you are <div class=code>". htmlentities($regexed_code) . "</div>"; //get rid of slashes added by the mysql_real_escape_string() $stage3 = stripslashes($stage2); echo "<pre>"; echo($stage2); echo "</pre>"; ?> Thanks a lot! Sean
  6. Right, Thanks. This is what I was looking for.
  7. Thanks for the replies. I see what you mean, however there won't always be code in the user's reply. I only want to highlight the code when there is code.
  8. Basically, I'm trying to take a string from the db and do two things. [*]Prevent html from being processed as html (htmlspecialchars() i think) [*]Recognize PHP code and highlight it. This is a reply system much like what I'm typing right now. For example 2, I want to be able to do this <?php echo "hello"; ?> I've researched a little and found a function called highlight_php(). The problem I run into now is that I only want to highlight php when it is needed. I am stuck as to where to go next. My thoughts would be 2 regex functions, however I don't know which one to call first. Any suggestions? Everything is appreciated
  9. I took out the output buffering and that did nothing for me. I tried echoing text on the page index page, and it's not showing up. bizarre needless to say
  10. This error is very bizarre since I can't seem to debug it. When I require my header, it is included. When I require my footer, it is not. I am 100% the paths are correct, and I tried another file to make sure it wasn't the footer causing the error. Here's the code for the header, footer, and index. If you need to see anything else just tell me. header <?php ob_start(); ?> <?php ini_set('session.cookie_domain', '.domain'); ?> <?php ini_set('display_errors','On'); ?> <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <link rel='stylesheet' href='includes/css/reset.css' type="textcss"/> <link rel="stylesheet" href="includes/css/style.css" type="text/css"/> <title>Domain</title> </head> <?php require('classes/common.inc.php'); $common = new common(); if($common->_truesession()) { $hsuser = $_SESSION['username']; } $common->_cookiecheck(); $db = $common->_db(); echo "<ul>"; echo "<li><a href=domain.com>Domain</a><ul>"; $query = $db->_query("select * from links where id > 1"); while($row = $db->_assoc($query)) { $name = $row['name']; $link = $row['url']; echo "<li><a href=".$db->_out($link).">".$db->_out($name)."</a></li>"; } echo "</ul></li></ul>"; ?> index <?php require('includes/header.php'); ?> <?php ?> <?php require('includes/footer.php'); ?> footer <?php echo "<ul>"; echo "<li><a href=about.php>About</a></li>"; if(!$common->_truesession()) { echo "<li><a href=register.php>Register</a></li>"; } echo "</ul>"; $year = date('Y'); echo "&copy $year <a href='http://domain.com'>Domain</a>"; ob_end_flush(); ?>
  11. When I tried to add require('db.inc.php'); $db = new db(); at the beginning of the class I get syntax error, unexpected T_REQUIRE, expecting T_FUNCTION
  12. When I use another class inside one class, I get this error The code is here <?php require ('db.inc.php'); $db = new db(); class common { function _cookiecheck() { if(!isset($_SESSION['username'])) { if(isset($_COOKIE['username'])&&isset($_COOKIE['password'])) { $pass = $db->_safestring($_COOKIE['password']); $user = $db->_safestring($_COOKIE['username']); $check = _query("select password from users where username='{$user}'"); if($check) { $_SESSION['username'] = $user; } } } } } ?> I get the error on the line when I call $db->_safestring(); Thanks for the help
  13. thanks guys! Worked perfectly. I'll remember this for next time.
  14. Here's the code, I had used the query in the header, and now I'm using it to display the links in a table. What happens is that it only returns the first row and not the second third or fourth rows. When it does display the first row, it'll display it a lot of times. Here it is <?php if($_GET['place']==addnetwork){ //display current networks echo "<table border=1>"; echo "<tr><td>Network Name</td><td>URL</td></tr>"; while ($query1 = mysql_fetch_assoc(mysql_query("select name,url from s_links"))) { $networkname = $query1['name']; $networkurl = $query1['url']; echo "<tr><td>$networkname</td><td>$networkurl</td></tr>"; } echo "</table>"; } ?>
  15. html stacks, I want it to become in line, and when I use the display:inline-block; it doesn't work. How do I go about doing so?
  16. MY question is quite dumb, but I am stuck in my css and I don't know what to do. Anyways, I have three items in my header, title, links, and login. However, by default html stacks everything, instead of inline where </br> would create a new line. I researched something about display: inline-block, however I've tried it multiple times at many places and it still won't work. Here's my code. body { background:url('/images/background.jpg'); background-repeat: repeat-y repeat-x; font-family:‘Gill Sans’, ‘Lucida Grande’, ‘Lucida Sans Unicode’, Verdana, Helvetica, Arial, sans-serif; font-size:14px; color:#1d1d1d; width: 100%; display: inline-block; } a { text-decoration:none; color: red; } #headertop { background-color:#1d1d1d; color:#d4d4d4; padding-bottom: 15px; position:relative; width: 100%; display: inline-block; } #headertop table{ color:#d4d4d4; ; } #headertop ul{ text-decoration: none; display: inline-block; } #seconddrop{ } #headerpages { display:inline-block; list-style-type: none; } #login{ float; right; } .error { color:#1d1d1d; } .main { position: relative; width: 1000px; margin-left: auto; margin-right: auto; } #footer { position: relative; padding-bottom: 5px; width: 100%; background-color:#1d1d1d; color:#d4d4d4; display: inline-block; } #footer li { } #footerdrop { float:right; } #copyright { float:right; } any suggestions? thanks!
  17. Doesn't matter now. I'm deciding to use output buffering
  18. Anyways, it won't let me do it in the footer. My header contains navigations and such which is obviously html. I want the errors to appear under the header and above the form. I know that guide explained how to do it, but I keep my registry where it runs the else statement.
  19. So is it ok to put the title and headers in the footer?
  20. Sure, but if I have my form processing in the else statement, how can I put it before the errors?
  21. I added a new line in an attempt to redirect if the user first of all and the error changed to that line, it's obviously still applicable to the other header(). if(isset($_SESSION['username'])) { header('Location: index.php'); } The error I'm getting is The header looks like this at the top <?php ini_set('session.cookie_domain', '.ns.com'); ?> <?php session_start(); ?> <head> <link rel="stylesheet" href="includes/css/style.css" type="text/css"/> <link rel='stylesheet' href='includes/css/reset.css' type="textcss"/> <title>NS</title> </head> <?php require('db.inc.php'); require('cookiecheck.php'); Sorry about not posting that. I was hesitating to do so, but I feared it was something in the code.
  22. Before asking, I have read this. http://www.phpfreaks.com/forums/index.php?topic=37442.0 I am just confused why my header still doesn't work. I don't think I'm outputting anything in the else statement where my header(Location: 'registerconf.php') is; Here's the code <?php require('includes/header.php'); ?> <?php //VARIABLES $submit = mysql_real_escape_string($_POST['submit']); $username = mysql_real_escape_string($_POST['username']); $user = $_POST['username']; $firstname = mysql_real_escape_string($_POST['firstname']); $lastname = mysql_real_escape_string($_POST['lastname']); $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $passwordconf = mysql_real_escape_string($_POST['passconf']); $ageconf = mysql_real_escape_string($_POST['ageconf']); $tosconf = mysql_real_escape_string($_POST['tosconf']); $loweruser = strtolower($username); $checkuser = mysql_query("select * from users where username_lower='{$loweruser}'"); $userexists = mysql_fetch_assoc($checkuser); $emailexistsquery = mysql_query("select * from users where email='{$email}'"); $emailexists = mysql_fetch_assoc($emailexistsquery); /*CHECKS * Many checks need to be done, the checks will also be done in order. The order will * be listed here * */ if(isset($_POST['submit'])) { if(empty($username)||empty($firstname)||empty($lastname)||empty($email)||empty($password)||empty($passwordconf)){ echo('Please fill out all fields!<br/>'); }else{ if($userexists) { echo "Username $username already exists"; }else{ if(strlen($username)>15||strlen($username)<5) { echo "Username must be between 5 and 15 characters"; }else{ if (!preg_match('/^[a-zA-Z0-9]+$/', $user)) { echo "Username can only contain letters and numbers with no spaces"; }else{ if(strlen($firstname)>20) { echo "Your first name cannot be larger than 20 characters"; }else{ if(!preg_match('/^[A-Z]{1}[a-z]+$/', $firstname)) { echo "Your first name can only contain letters and must start with a capital followed by lowercase letters"; }else{ if(strlen($lastname)>20) { echo "Your last name cannot be larger than 20 characters"; }else{ if(!preg_match('/^[A-Z]{1}[a-z]+$/', $lastname)) { echo "Your last name can only contain letters and must start with a capital followed by lowercase letters"; }else{ if(strlen($email)>40) { echo "Email cannot be longer than 40 characters"; }else{ if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Invalid Email"; }else{ if($emailexists) { echo "Email already exists"; }else{ if(strlen($password)<5||strlen($password)>30) { echo "Password must be between 5 and 30 characters"; }else{ if($password!=$passwordconf) { echo "Passwords don't match"; }else{ if($ageconf=='') { echo "You must be 16 or older to register"; }else{ if($tosconf==''){ echo "You must agree with the Terms of Service"; }else{ //add to database $mdpass = md5($password); $rand = rand('12345','54321'); $activekey = time()+$rand; $query = "insert into users set username='{$username}', username_lower='{$loweruser}', firstname='{$firstname}', lastname='{$lastname}', email='{$email}', activationcode='{$activekey}', password='{$mdpass}'"; $query2 = mysql_query("select * from users where username='{$username}'"); mysql_query($query); $sqluserid = mysql_fetch_assoc($query2); $userid = $sqluserid['id']; $to = $email; $subject = "Activate your account"; $message = "Welcome to Site! $firstname! </br> Thank you for taking your time to register an account for the Site Networks your click the link below to activate your account! </br></br> <a href=ns.com/registerconf.php?pid=$userid&activate=$activekey; "; header('Location: registerconf.php'); } } } } } } } } } } } } } } } echo ""; } echo "<table> <form name='login' method ='POST' action='register.php'> <tr><h3>Register your account and get access to all of the Networks!<h3></tr> <tr><td>Username</td><td><input type='text' name='username' value=".$username."></td></tr> <tr><td>First Name</td><td><input type='text' name='firstname' value=".$firstname."></td></tr> <tr><td>Last Name</td><td><input type='text' name='lastname' value=".$lastname."></td></tr> <tr><td>Email</td><td><input type='text' name='email' value=".$email."></td></tr> <tr><td>Password</td><td><input type='password' name='password'></td></tr> <tr><td>Confirm Password</td><td><input type='password' name='passconf'></td></tr> <tr><td>I am 16 or older</td><td><input type='checkbox' name='ageconf'></td></tr> <tr><td>I agree with the <a href='tos.php'>terms of service</a></td><td><input type='checkbox' name='tosconf'></td></tr> <tr><td><input type='submit' name='submit' value='Register'> </form> </table> "; ?> <?php require('includes/footer.php'); ?> It might be the sql statement but I need that for the user id. Thanks
  23. So basically I am trying to make a registry form. In this, one of the checks finds out if the input is only text and numbers, (I also want to know how to allow no spaces). In my code, it will always return "Username can only contain letters and number" no matter the input. I figured it was something wrong with the regex. Here's the code <?php require('includes/header.php'); ?> <?php //VARIABLES $submit = mysql_real_escape_string($_POST['submit']); $username = mysql_real_escape_string($_POST['username']); $user = $_POST['username']; $firstname = mysql_real_escape_string($_POST['firstname']); $lastname = mysql_real_escape_string($_POST['lastname']); $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $passwordconf = mysql_real_escape_string($_POST['passconf']); $loweruser = strtolower($username); $checkuser = mysql_query("select * from users where username_lower='{$loweruser}'"); $userexists = mysql_fetch_assoc($checkuser); // if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { // echo "Invalid Email"; /*CHECKS * Many checks need to be done, the checks will also be done in order. The order will * be listed here * */ if(isset($submit)) { if(empty($username)||empty($firstname)||empty($lastname)||empty($email)||empty($password)||empty($passwordconf)){ echo('Please fill out all fields!<br/>'); }else{ if($userexists) { echo "Username $username already exists"; }else{ if(strlen($username)>15||strlen($username)<5) { echo "Username must be between 5 and 15 characters"; }else{ if (!preg_match('/^[a-zA-Z0-9]$/', $user)) { echo "Username can only contain letters and numbers"; }else{ } } } } } echo "<table> <form name='login' method ='POST' action='register.php'> <tr><h3>Register your Suriak account and get access to all of the Suriak Networks!<h3></tr> <tr><td>Username</td><td><input type='text' name='username' value=".$username."></td></tr> <tr><td>First Name</td><td><input type='text' name='firstname' value=".$firstname."></td></tr> <tr><td>Last Name</td><td><input type='text' name='lastname' value=".$lastname."></td></tr> <tr><td>Email</td><td><input type='text' name='email' value=".$email."></td></tr> <tr><td>Password</td><td><input type='password' name='password' value=".$password."></td></tr> <tr><td>Confirm Password</td><td><input type='password' name='passconf' value=".$passwordconf."></td></tr> <tr><td><input type='submit' name='submit' value='Register'> </form> </table> "; ?> <?php require('includes/footer.php'); ?>
  24. Also, I do have <?php ini_set('session.cookie_domain','.suriak.com')?> <?php session_start(); ?> I just cut it out and went to the statement
×
×
  • 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.