Jump to content

SmexyPantsGnome

New Members
  • Posts

    9
  • Joined

  • Last visited

SmexyPantsGnome's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the input. Right now I am just trying to get code to work on a local computer, which seems all the coding syntax errors are fixed. I am looking over php example of "Simple login management" on various websites. I have no plans releasing this to a dedicated website yet.
  2. Thanks, think solved ever possible senario: <?php session_start(); $_SESSION['dbhost'] = $_POST['dbhost']; $_SESSION['dbuser'] = $_POST['dbuser']; $_SESSION['dbpass'] = $_POST['dbpass']; $_SESSION['dbname'] = $_POST['dbname']; ?> <!store variables in a session> <html> <head> <link rel="stylesheet" href="style.css"> </head> <body> <?php if (!empty($_SESSION['dbname'])) { echo "Database connection settings are saved for ".$_SESSION['dbname'].".<br>"; $con = mysqli_connect($_SESSION['dbhost'],$_SESSION['dbuser'],$_SESSION['dbpass']); if (mysqli_connect_errno()) { die("Failed to connect to your database with the saved settings.<br>"); } else { //create database if it doesn't exist $sql="CREATE DATABASE ".$dbname; if (mysqli_query($con,$sql)) { echo "Database ".$dbname." created successfully<br>"; } //Get saved account info $con = mysqli_connect($_SESSION['dbhost'],$_SESSION['dbuser'],$_SESSION['dbpass'],$_SESSION['dbname']); $sql="SELECT count(*) FROM account"; if (mysqli_query($con,$sql)) { //found account table $query = mysqli_fetch_assoc(mysqli_query($con,$sql)); $count = $query["count(*)"]; if ($count == 0) { //account table is empty echo "Detected your account has not been configured yet: <br>"; echo 'Click <a href ="setup_account.html">here</a> to configure.<br><br>'; } else { //found previous account info $sql = "SELECT ircnick FROM account"; $query=mysqli_fetch_assoc(mysqli_query($con,$sql)); $user = $query["ircnick"]; echo "Found your previous saved settings: <br>"; echo 'If you want to change the settings for '.$user.' click <a href="setup_account.html">here</a>.<br>'; } } else { //account table does not exist $sql = "CREATE TABLE account(ircserver CHAR(6), ircnick CHAR(25), ircpass CHAR(99), ircchannel CHAR(25))"; if (mysqli_query($con,$sql)) { //create account table echo "Detected your account has not been configured yet: <br>"; echo 'Click <a href ="setup_account.html">here</a> to configure.<br><br>'; } else { //error with creating the table echo "Error configuring settings: ".mysqli_error($con)."<br>"; } } mysqli_close($con); } }
  3. I do believe it is caused when 'account' table doesn't exist yet.
  4. Checking if php function mysqli_fetch_assoc() been removed from newer php versions. Running LAMP Apache 2.4.7 PHP 5.5.9 MySQL 5.5.38 Running WAMPserver Apache 2.4.9 PHP 5.5.12 MySQL 5.6.17 LAMP system, this code works fine: <?php session_start(); $_SESSION['dbhost'] = $_POST['dbhost']; $_SESSION['dbuser'] = $_POST['dbuser']; $_SESSION['dbpass'] = $_POST['dbpass']; $_SESSION['dbname'] = $_POST['dbname']; ?> <!store variables in a session> <html> <head> <link rel="stylesheet" href="style.css"> </head> <body> <?php if (!empty($_SESSION['dbname'])) { echo "Database connection settings are saved for ".$_SESSION['dbname'].".<br>"; $con = mysqli_connect($_SESSION['dbhost'],$_SESSION['dbuser'],$_SESSION['dbpass'],$_SESSION['dbname']); if (mysqli_connect_errno()) { die("Failed to connect to your database with the saved settings.<br>"); } else { echo "Successfully connected to the database.<br><br>"; } $sql = "SELECT count(*) FROM account"; $query=mysqli_fetch_assoc(mysqli_query($con,$sql)); $count = $query["count(*)"]; if ($count == 0) { echo "Detected your account has not been configured yet: <br>"; echo 'Click <a href ="setup_account.html">here</a> to configure.<br><br>'; } else { $sql = "SELECT ircnick FROM account"; $query=mysqli_fetch_assoc(mysqli_query($con,$sql)); $user = $query["ircnick"]; echo "Found your previous saved settings: <br>"; echo 'If you want to change the settings for '.$user.' click <a href="setup_account.html">here</a>.<br>'; } } else { echo "Error saving your settings.<br>"; } ?> But on WAMP get this output: (!) Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\setup.php on line 44 Call Stack # Time Memory Function Location 1 0.0000 249936 {main}() ..\setup.php:0 2 0.0156 260184 mysqli_fetch_assoc() ..\setup.php:44 Trying to share my code with a friend who is using Windows.
  5. I have created this for account checking. This connects an auto-response bot to the irc channel: Responds to % prefix commands that someone types in the channel. I added $_SOCKETS now to see if account is valid. Plan to install https for added security on my webserver too. New code now uses $_SESSION: <!DOCTYPE html> <?php session_start(); ?> <!load the existing session from previous page> <html> <head> <link rel="stylesheet" href="style.css"> </head> <?php //forces webbrowser to clear buffer to show text, also adds a delay for loop function irc_clearbuffer() { if (ob_get_level() == 0) obstart(); for($i=0;$i<70;$i++) { print str_pad('',4096)."\n"; ob_flush(); flush(); usleep(1); } } $server = $_SESSION['server']; $name = $_SESSION['account_name']; $pass = $_SESSION['account_pass']; //connect to main server if ($server == "main") { $server = "irc.main.com"; $socket = fsockopen($server, 6667); stream_set_blocking($socket, 0); fputs($socket, "USER ".$name."\n"); fputs($socket, "PASS ".$pass."\n"); fputs($socket, "NICK ".$name."\n"); echo "Attempting to connect to ".$server."<br>"; } //connect to alt server elseif ($server == "alt") { $server = "irc.alt.com"; $socket = fsockopen($server, 6667); stream_set_blocking($socket, 0); fputs($socket, "PASS ".$pass."\n"); fputs($socket, "NICK ".$name."\n"); fputs($socket, "USER ".$name." ".$name." ".$server." :".$name."\n"); echo "Attempting to connect to ".$server."<br>"; irc_clearbuffer(); fputs($socket, "JOIN #".$name."\n"); } else { die("You forgot to select a server. Please login again."); } for ($i=0;$i<100;$i++) { //display new data that irc server sends while ($data = fgets($socket, 1024)) { //reads up to 1024 characters from the irc server if ($server == "irc.main.com") { $trim_data = substr(nl2br($data),25,18); if ($trim_data == "Login unsuccessful") { session_destroy(); echo "Retry login<br>"; die($trim_data); } } if ($server == "irc.alt.com") { $trim_data = substr(nl2br($data),22,23); if ($trim_data == "You have not registered") { echo "Retry login<br>"; session_destroy(); die($trim_data); } } } irc_clearbuffer(); } fclose($socket); ?>
  6. Yes thats true This is just a hobby project that I'm working on for fun. But I got requested from multiple poeple wanting to try it out now. So now I'm looking into adding account login controls on top of what I already have. Don't want to accidentally have one user load settings that another user setup.
  7. Can't believe I wasted so much coding time doing it this way. Storing saved variables in MySQL for account details is alot easier. This connects to a IRC server that requires name and password. Login page loads variables to accounts table with columns (Nick, Pass, Channel) If someone give the wrong pass it will fail to load the Irc info. I will also look up examples on using $_SESSION.
  8. Guess need to rethink my site layout then. A single page generating content would be easier on the hard drive space. The way I've been verifying accounts is when use first logs in it tracks the client's IP address update the MySQL database. If anyone ever connects to a page where account IP does not match prevent the php code from loading. Example: User signs in to page as user123. Then they manually type in http://myipaddress/anotheruser/ nothing will show up. Unless it was from the same IP address as the last time account anotheruser signed in.
  9. I am unsuccessfully able to do the following: User creates an account After login, checks server if user has their own folder created If doesn't exist, create it Copy files from source_code to this new folder My code does create a folder, but no files appear inside it. Been trying to find an example with google search for the past 3 days with no luck. I am running LAMP on Linux Mint OS to run my PHP webpages. Can anyone tell me if issues with this section of coding? <?php function wait_time($seconds) { $seconds = abs($seconds); if ($seconds < 1): usleep($seconds*1000000); else: sleep($seconds); endif; } $file1 = "blank.html"; $file2 = "channel_video.php"; $file3 = "clear_playlist.php"; $file4 = "confirm.html"; $file5 = "index.html"; set_time_limit(0); //prevent script from timing out $account = $_POST["account_name"]; $src = "source_code/"; $dst = $account."/"; echo 'Setting up your account page ->.'; mkdir($account, 0777, true); echo '.'; //create folder with full write permissions wait_time(2000); //wait 2 seconds before copying files over copy($src.$file1, $dst.$file1); echo '.'; wait_time(2000); //wait 2 seconds before copying files over copy($src.$file2, $dst.$file2); echo '.'; wait_time(2000); //wait 2 seconds before copying files over copy($src.$file3, $dst.$file3); echo '.'; wait_time(2000); //wait 2 seconds before copying files over copy($src.$file4, $dst.$file4); echo '.'; wait_time(2000); //wait 2 seconds before copying files over copy($src.$file5, $dst.$file5); echo '.<- setup finished<br>'; ?> Thanks for any input you can provide.
×
×
  • 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.