PHP - Php To Create New .js File For Each Registered User
Hello everybody,
This is my first post here and I am beginner in PHP world in terms of writing the code to serve my own purposes. Well I am building a web app and basically it's a calendar which pulls information from .js file. Now I have thinking for the past couple of days how can I accomplish that each user that registers on the site manipulates its own .js file because information from .js file will be shown on calendar. Let me tell you how it's currently set up: 1. JavaScript file with particular static name is called under the script that is placed on index.php and the data is displayed on the page itself. So I would love to have is set it up like this: 1. Index page contains login form - Each registered/logged in user will have its own session 2. User registers and based on username/email new .js file is created out of a blank template and it is named based on user's username 3. user is then redirected to the calendar index which contains javascript that cals out that appropriate .js file based on the what user is logged in and displays data to the calendar I am not sure if that is doable with PHP or not but that's my thinking how it can be done if it's doable. I am open for any kind of suggestions how all this can be put together and if you do have better ideas I would love to hear from you. Similar TutorialsHello, i'm trying to get the number of users that registered today and the number of users that registered yersterday (seperate), i've got this field in mysql: 'registertime' which stores data in this format 2011-11-14 14:53:49 also i have the field 'time' in the same format that updates everytime the user logs in. Now previously i wanted to find out users online in last 24 hours, the code i used for that is this: Code: [Select] $query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de' AND time BETWEEN DATE_SUB( NOW(), INTERVAL 24 HOUR ) and NOW() "; $queryerg = mysql_query($query) OR die(mysql_error()); while($row = mysql_fetch_array($queryerg)){ $customers_on_de_24 = $row[0]; } How could i edit that to select the count just by date and ignore the time (hours minutes seconds) ? Hello everyone.
I have a fully working form that gets data from a user (with $_post array) , and stores it in a database (mysql).
After successfulIy filling the form, I refer him to the "dashboard" page. In this page, i am having trouble to get his details from the database. How should I recognize him as the user that just registered?
should I use a $_post? or maybe a session? could you please give me a clue how to solve this?
I can't find out whats the problem here, would appreciate some input in how to think building my "if".
The problem is that I don't seem to catch if an email exists, nor if user exists and neither can I create a new user :/.
Appreciate your help alot!
<?php // Start the session in case of errors to display within the page of user creation session_start(); $err_msg = array(); $errflag = false; // Check if the submit button was pressed if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_POST['submit'] === 'Skapa') { // Crypt password $options = ['cost' => 10]; $username = strip_tags($_POST['uname']); $password = strip_tags(password_hash($_POST['pword'], PASSWORD_DEFAULT, $options)); $email = strip_tags($_POST['uname'], '@'); // Check so all the fields are filled if ($_POST['uname'] == '' || $_POST['pword'] == '' || $_POST['pwordcheck'] == '') { $err_msg[] = 'Please enter all fields<br>'; $errflag = true; } // See if passwords and confirm matches if ($_POST['pword'] !== $_POST['pwordcheck']) { $err_msg[] = 'Passwords doesn\'t match!<br>'; $errflag = true; } // Check password length, atleast 8 characters if (strlen($_POST['pword']) < 7) { $err_msg[] = 'Password must be atleast 8 characters long'; $errflag = true; } // Check if email exists include_once('../includes/db.inc.php'); $db = new PDO(DB_INFO, DB_USER, DB_PASS); $sql = "SELECT COUNT(*) AS count FROM movies WHERE email = :emailadress"; $stmt = $db->prepare($sql); $stmt->bindParam(':emailadress', $email); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row > 0) { $err_msg[] = 'Email already taken!'; $errflag = true; $db = NULL; } // Check if user exists include_once('../includes/db.inc.php'); $db = new PDO(DB_INFO, DB_USER, DB_PASS); $sql = "SELECT uname FROM users WHERE uname = :username"; $stmt = $db->prepare($sql); $stmt->bindParam(':username', $username); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row > 0) { $err_msg[] = 'User already exists'; $errflag = true; $db = NULL; } if ($errflag = false) { // Everything passed, create the user! include_once('../includes/db.inc.php'); $db = new PDO(DB_INFO, DB_USER, DB_PASS); $sql = "INSERT INTO users (uname, pword, email) VALUES (:username, :password, :emailadress)"; $stmt = $db->prepare($sql); $stmt->bindParam(':username', $username); $stmt->bindParam(':password', $password); $stmt->bindParam(':emailadress'); $stmt->execute(); $_SESSION['uname'] = $username; header('Location: ../template/header.php'); exit; } // If any error, send the user back and display messages if ($errflag == true) { $_SESSION['err_msg'] = $err_msg; session_write_close(); header('Location: ../user/create.php'); exit; } } else { $_SESSION['err_msg'] = $err_msg; session_write_close(); header('Location: ../user/create.php'); exit; } ?> How would I go about creating a new user email account that can be accessed via my cpanel mail scripts (RoundCube, SquirrelMail, etc.), in PHP. Hi, i coded a very simple forum "website" with registration, login, and a place where everyone posts comments. I wanted to make some sort of profile page for each user so they would each have their own URL too (e.i. test/barney or test/simpsons). each of these pages would have different content, depending on what barney or simpsons puts on that page. i've been looking everywhere trying to find documentation but i don't think i know how to search it correctly. I checked a lot of mod_rewrite documentation but i don't understand if i'm suppose to call a php function to create a profile page or something. Any guidance would be greatly appreciated Thanks! Hi Guys, have you got an idea how I can create a user management system with login and pw, please? I tried the below, but when I click on the "ADD NEW USER" button nothing happens <div> <fieldset> <legend>USER DETAILS</legend> <table> <tr> <td align="right"><a title='NAME' href='user_edit.php?id=1'>NAME</a></td> <td> <input class="norm" type="text" name="name" id="name" /></div> </td> <td align="right"><a title='SURNAME' href='user_edit.php?id=2'>SURNAME</a></td> <td> <input class="norm" type="text" name="surname" id="surname" /></div> </td> </tr> <tr> <td align="right"><a title='E-MAIL ADDRESS' href='user_edit.php?id=3'>E-MAIL ADDRESS</a></td> <td colspan="4"> <input class="norm" type="text" size="57" name="e-mail" id="e-mail" /></div> </td> </tr> <tr> <td align="right"><a title='LOGIN' href='user_edit.php?id=4'>LOGIN</a></td> <td> <input type="text" name="login" id="login" /></div> </td> <td align="right"><a title='PASSWORD' href='user_edit.php?id=5'>PASSWORD</a></td> <td> <input class="norm" type="text" name="password" id="password" /></div> </td> </tr> </table> </fieldset> </div> <br /> <div> <fieldset> <input type='submit' name='delete' value='DELETE USER' onclick='confirm("ARE YOU SURE?");'/> <input type='submit' name='add' value='ADD NEW USER'/> </fieldset> </div> cheers, ozzo Whats going on PHPfreaks? So this is what I've been trying to do for the whole weekend and just can't figure it out. I want to let users create new pages on my site like wiki style but dont want a wiki or drupal or joomla or any of that. I know its possible with: $text = $_POST['text']; $file = fopen($text . ".php","x"); fwrite($file,"Welcome to your new page!"); but I'm not sure how to integrate it. For further clarification here's an example: You come to the site and there is a list of previously made user pages all with their own user generated name. What I want to have is a create new page button that opens a new page allows the user to upload images then submit it to the database and upon refresh of the page their page is now in the list. The create new page resets and is available for another user and on and on. Any help will be appreciated. I need to get this done it's driving me crazy. Hi, I've always used PHP code in my websites in a procedural manner as I come from a html/css background. Now that I want to do projects with more complexity I'm thinking I need to approach development in a more Object Oriented fashion. My question is more a theoretical one. I'm creating a User class and I'm not sure on what is the best practise for putting my functions etc. and where to call them. My project will have 2 different users (Admin & End User) so is it correct to say that the User class should encapsulate all the functions of both of these users ? By that I mean create/delete/modify user, login & change password/forgotten password functionality rather than having a seperate Login class Should I only call the database functions within these methods of the user class as opposed to calling them on the php page where the form data is posted ? For example, if a user logins in and when the form data is posted I currently open a connection, validate data, run the query. In an OO approach would I have just one User class method thats relevant to a particular page functionality ? Say, in pseudo code, for handling a login request loginRequest.php Code: [Select] include User class try { create new user User(); User::login(); } catch Exception() and should my User class look something like this class.User.php Code: [Select] include DBase class class User { var name, var email, var password, function validateInput (email, password) { if (!valid input) throw Exception else return true } function login (email, password){ try { database connection validateInput(); sql to see if user exists and login } catch Exception } } Apologies for this being a bit long winded! thanks tmfl Hello,
I'm embarking on a pretty ambitious task and I need some bits of information here and there.
One of the functions I need to achieve is to build a query or array of photos based on a background image and user input.
So imagine that I have a box and within that box is a column of three rows.
I need to have three different bits of data be placed into each of the subsequent rows and then an image is taken of these three pieces of data overlaying the background photo.
Then stored somewhere with an incremented identifier to be pulled later.
I think I can already begin to imagine how it would work but what eludes me is a "screenshot" function to generate the images. I'm looking for .png or .jpg end result files with fixed width/height and item placement.
Thank you for any help
Hi all I'm trying to create an XML file to be used within Excel. The data is drawn dynamically from my database depending on the information supplied by the user. However when I run it, I get a complain from Excel about some missing whitespace. any ideas? Code: [Select] <?php $output='<?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <Author>Europcar</Author> <LastAuthor>Europcar</LastAuthor> <Created>2011-10-28T10:48:37Z</Created> <Company>Europcar</Company> <Version>11.9999</Version> </DocumentProperties> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>11760</WindowHeight> <WindowWidth>15195</WindowWidth> <WindowTopX>480</WindowTopX> <WindowTopY>75</WindowTopY> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Vertical="Bottom"/> <Borders/> <Font/> <Interior/> <NumberFormat/> <Protection/> </Style> </Styles> <Worksheet ss:Name="Sheet1"> <Table ss:ExpandedColumnCount="'.$columns.'" ss:ExpandedRowCount="'.($count+5).'" x:FullColumns="1"x:FullRows="1">'; //$output.='<Column ss:AutoFitWidth="0" ss:Width="50"/>/n'; $output.='<Row>'; foreach ($titles as $value){ if(is_numeric(substr($value,0,1))){ $value=substr($value,1); } $output.='<Cell><Data ss:Type="String">'.$value.'</Data></Cell>'."LF"; } /*$output.='</Row>'; foreach ($dataOut as $value){ $output.='<Row>'; foreach($value as $values){ if(strlen($values)<1){ $values=" "; } $output.= '<Cell><Data ss:Type="String">'.$values.'</Data></Cell>'; } $output.='</Row>'; }*/ $output.=' </Table> <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <Selected/> <Panes> <Pane> <Number>3</Number> <ActiveRow>'.($count+5).'</ActiveRow> <ActiveCol>'.$columns.'</ActiveCol> </Pane> </Panes> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions> </Worksheet> </Workbook>'; I'm using a php $_POST variable as the name of a file that I want to create. fopen() , according to my understanding open the file if it exists or creates it if it doesn't. $Ref = $_POST['Ref']; I using each reference element of $Ref as the name of a file in a certain directory. So if $Ref[$i] exists as a file name in a certain directory, append to the file, if it doesn't create the file in that directory and write to it. Do I use the file path of the file within fopen()? fopen(./References/$Ref,a) or fopen(./References/$Ref,w)? I am trying create my xml file in this format: Code: [Select] <?xml version="1.0" encoding="UTF-8" ?> - <playlist id="Adobe"> <vid desc="5 minute cardio warm-up" contenu="side jumps, arm curls ..." src="videos/set2_first_5min.flv" thumb="thumbs/set2_first.png" /> <vid desc="5 minutes of no rest workout moves" contenu="Football drills, front kicks ..." src="videos/set2_second_5min.flv" thumb="thumbs/set2_second.png" /> <vid desc="last 5 minutes of Set 1" contenu="MC Hammer ..." src="videos/set2_third_5min.flv" thumb="thumbs/set2_third.png" /> <vid desc="5 minute cardio warm-up" contenu="jumping jacks, presses and squats" src="videos/Set1_first.flv" thumb="thumbs/set1_first.jpg" /> <vid desc="5 minutes of no rest workout moves" contenu="shin kicks ..." src="videos/Set1_mid.flv" thumb="thumbs/set1_mid.jpg" /> <vid desc="last 5 minutes of Set 1" contenu="MC Hammer ..." src="videos/Set1_last.flv" thumb="thumbs/set1_last.jpg" /> </playlist>[/color] I'm not having trouble getting and looping through the data from mySQL. I'm getting confused with what's a child element, attribute node, and attribute value. Can someone who has worked with the DOMDocument steer me in the right direction? sample code is the best request Thanks! Hey! I am making a comment system for my blog I'm making. The way I want it, is that when a comment is posted, it grabs the id of the post it's referring to, then creates a file called comment(POST ID HERE).txt.. I have that down, however I cannot for the life of me figure out how I can make it an increment, so it can make no more than 500, but everytime a comment is posted it will keep making the files go up like: comment1.txt comment2.txt comment3.txt Etc... Thanks very much, happy holidays! guys i want to to create a html invoice to pdf file how can i do that ...by using which library...can any one help me out? i am working on a report tool was developed in linux. Currently i am developing same thing in windows. So i need to have a knowledge in creating batchfiles in php with windows Os. Suggestions/Help needed urgently Hello, please let me know how to write xml file, i read somewhere we can use psql.....anyone knows please help! Thanks Hey, i'd like to extract filenames from my database and present them as a downloadable zip-file to my users. I found a usefull function on http://davidwalsh.name/create-zip-php and thought i could work that out to my needs, but on this function itself (before using it), i get an error.. on the following line: if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { i get: Parse error: syntax error, unexpected ')', expecting '(' i dont get it, dont think there is actually an error in the function.. does it mean that the php installed on the server i use, cant handle this function or anything? my phpinfo: http://dwarsfluit.davidvandiepen.nl/test.php the function is: Code: [Select] <?php /* creates a compressed zip file */ function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in... if(is_array($files)) { //cycle through each file foreach($files as $file) { //make sure the file exists if(file_exists($file)) { $valid_files[] = $file; } } } //if we have good files... if(count($valid_files)) { //create the archive $zip = new ZipArchive(); if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($valid_files as $file) { $zip->addFile($file,$file); } //debug //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); } else { return false; } }?> thanks for helping! This should create a gb.txt in the local folder but its not creating it? What is wrong with it pls help <html> <head> <title>Guestbook</title> </head> <body> <?php extract($_REQUEST); ?> <?php if(isset($submit)) { saveGuestbook($name, $email, $comments); showGuestbook(); } elseif($check){ showGuestbook(); }else{ callForm(); } ?> <?php function showGuestbook() { echo "<body bgcolor='#DAE5CD'>"; echo "<font color='#cc3333' size='+2'><b>Thank You!</b></font> <br><br>"; $data = file("gb.txt"); foreach ($data as $line) { $line = rtrim($line); echo "<hr>"; list($name, $email, $comments) = split ("\t", $line); echo "Name: $name<br>"; echo "Email: $email<br>"; echo "Comments: $comments<br>"; } echo "<hr><p><a href = 'guestbook.php'>Click here </a> to go back </p>"; } function saveGuestbook($nam, $mal, $com) { $fh = fopen("gb.txt"); $nameData = $nam. "\t"; fputs($fh, $nameData); $mailData = $mal. "\t"; fputs($fh, $mailData); $commnetsData = $com. "\n"; fputs($fh, $commnetsData); fclose($fh); } function callForm() { print <<<DONE <font color="#CC0000" size="+2">Please sign our guestbook</font> <br > <br > <form name="Guestbook" method="post"> <table bgcolor="#DAE5CD"> <tr> <td valign="top">Name: </td> <td><input type="text" name="name" size="25" value="Your Name"></td> </tr> <tr> <td valign="top">E-mail:</td> <td><input type="text" name="email" size="25" value="example@mail.com"></td> </tr> <tr> <td valign="top">Comments:</td> <td><textarea rows="5" cols="30" name="comments">Comments</textarea></td> </tr> <tr> <td></td> <td align="right"><input type="submit" name="submit" value="submit"> <input type="reset" value="Clear"> </td> </tr> </table> </form> <p>Want to check out our <a href="guestbook.php?check=check"> guestbook?</a></p> DONE; } ?> </body> </html> Hi. I have wrote a simple login script. Works perfectly. Now as my users can only register one email address at the minute if you register two the same you get the default sql error pop up. I want my own error so at the beginning of my script i wrote the following code. however. It does not seem to be running. It does not create an error but still allows duplicate emails in the database. can anyone see the error of my ways? <?php session_start(); if(isset($_POST['create'])){ //script for checking if the email account already exists $qCheckEmail = "SELECT * FROM members WHERE email='".$_POST['email']."'"; $rCheckEmail = mysql_query($qCheckEmail); $Email = mysql_fetch_array($rCheckEmail); if($_POST['email'] == $Email['email']) {$emailDup = "This email account has already been registered";} else { //Process data for validation $forename = trim($_POST['forename']); $surname = trim($_POST['surname']); $email = trim($_POST['email']); $password = trim($_POST['password']); $gender = trim($_POST['gender']); $birthday = $_POST['birthday']; $creationdate = $_POST['creationdate']; $validationID = $_POST['validationID']; $accesslevel = trim($_POST['accesslevel']); $accountType = trim($_POST['accountType']); // then the rest of the login script here |