PNewCode
Members-
Posts
331 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
PNewCode's Achievements
-
Php and Laravel prevent duplicate entries help please
PNewCode replied to PNewCode's topic in PHP Coding Help
@Barand and @maxxd thank you for that info. Unfortunately I have no idea how to convert that to "Laravelese" as you said. Though that was a cool way of putting it haha. And yes the email is the username, because after getting a lot of grief from users in todays world of paranoid entries (and for good reason for many cases) I just changed it to entering a username instead of an email so that no email addresses are stored. There were already a few hundred pages that relied on it for other functions so I just left the column name in the database the same. I can't make heads or tales out of Laravel no matter how much I study it. It's like car mechanics to me... I can change the oil but rebuilding a motor is something my brain doesn't want me to know. Laravel, as it seems, is the motor. Spent the last month trying to comprehend this. No luck. I don't suppose either of you are for hire to make this function for me? -
Php and Laravel prevent duplicate entries help please
PNewCode replied to PNewCode's topic in PHP Coding Help
Thank you. The column name is "fname". Is that what you mean? In regular php I know how to check for duplicates and list them but thats as far as my knowledge goes. Laravel is a wild mess to me haha -
Hello everyone. I am wanting to prevent duplicate entries. This task is using laravel which I know little to nothing about. I'm putting this in PHP help because the file has php at the top of it. If this is the wrong place for this, then I apologize. The issue is that I googled for days and either I can't find the answer, or I can't translate what I find to fit what I need to do. The goal here is to prevent new users that sign up, to choose a username or screen name that already exists. I'm putting the code down below that I have to register the new users. The reason for this is because lately, I've had too many people replicating the same user names to make new accounts, either because they don't feel like asking for help when they forget the password or because they don't remember the answer to the question they created, or because they think making a new account gets them something new. So what I want to do is prevent duplicate user and screen names This laravel stuff is so far over my head that it's like trying to translate ancient egyptian cymbals for me. It took me over a week just to find where this file was haha Andy and all help is appreciated greatly NOTE: I didn't try to add any code to it yet because I'm incredibly nervous to destroy what is built because I don't understand this at all. <?php namespace App\Http\Controllers\Auth; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use App\Http\Controllers\Controller; use App\Services\ImageUploadService; use Illuminate\Support\Facades\Hash; use Illuminate\Auth\Events\Registered; use App\Providers\RouteServiceProvider; use Illuminate\Support\Facades\Validator; use Illuminate\Foundation\Auth\RegistersUsers; class RegisterController extends Controller { /* |-------------------------------------------------------------------------- | Register Controller |-------------------------------------------------------------------------- | | This controller handles the registration of new users as well as their | validation and creation. By default this controller uses a trait to | provide this functionality without requiring any additional code. | */ use RegistersUsers; /** * Where to redirect users after registration. * * @var string */ protected $redirectTo = RouteServiceProvider::HOME; /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('guest'); } /** * Get a validator for an incoming registration request. * * @param array $data * @return \Illuminate\Contracts\Validation\Validator */ protected function validator(array $data) { return Validator::make($data, [ 'fname' => ['required', 'string', 'max:255', 'alpha'], 'username' => ['required', 'string', 'max:255', 'alpha_num'], //'lname' => ['required', 'string', 'max:255'], 'password' => ['required', 'string', 'min:8'], 'image' => ['image', 'mimes:jpg,jpeg,png','mimetypes:image/jpg,image/jpeg,image/png'], 'question' => ['required', 'string', 'max:255'], 'answer' => ['required', 'string', 'max:255'], 'ip_address' => ['required', 'string', 'max:255'], ]); } /** * Create a new user instance after a valid registration. * * @param array $data * @return \App\Models\User */ protected function create(array $data) { return User::create([ 'fname' => $data['fname'], //'lname' => $data['lname'], 'email' => $data['username'], 'question' => $data['question'], 'answer' => $data['answer'], 'password' => Hash::make($data['password']), 'unique_id' => rand(time(), 100000000), 'ip_address' => $data['ip_address'], // Save the user's IP address ]); } /** * Handle a registration request for the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse */ public function register(Request $request) { $this->validator($request->all())->validate(); $user = $this->create($request->all()); event(new Registered($user)); /*$filename = now().$request->file('image')->getClientOriginalName(); $request->image->storeAs('images',$filename,'public');*/ //$filename = (new ImageUploadService())->upload($request->file('image'), 'images'); //$user->update(['img'=>$filename]); $users = User::where('id','!=',$user->id)->get()->modelKeys(); foreach($users as $u){ $user->conversations()->create()->users()->attach($u); } $this->guard()->login($user); if ($response = $this->registered($request, $user)) { return $response; } return $request->wantsJson() ? new JsonResponse([], 201) : redirect('login.php'); //: redirect($this->redirectPath()); } }
-
Php escape string with GET function issue with apostrophe
PNewCode replied to PNewCode's topic in PHP Coding Help
@mac_gyver @jodunno @Barand I solved it. It took me following up with you all to realize what the issue was. It was in SENDING the value. So I made the adjustment below with what was suggested in here and it works perfectly In the URL I changed it to goup1=" . html_entity_decode(".$group22.".......... Good grief. I can't believe I spent over a week on this and thats all I had to do. Well, and make a better connection like you all stated too. Thank you all so much. I appreciate your help a LOT! -
Php escape string with GET function issue with apostrophe
PNewCode replied to PNewCode's topic in PHP Coding Help
@jodunnocourrect tourney is the table name. The reason why that information work for all the other values is because it's passing that information in the url. Below is an example url that works. The goupno and linkno are translated in this url to the database columns (in this example the columns are named group43 and link43) The reason I did this, is to have one page to use for all of the updates for 73 other entries. Below is a working example. Then I'll show the non working example working example (and all other entries work without an apostrophe) https://www.thewebsite/test.php?link1=https://www.youtube.com/watch?v=7WOR-Yj4fOk&group1=musicvideo - Dont be angry - YouTube&groupno=group43&linkno=link43 non working example https://www.thewebsite/test.php?link1=https://www.youtube.com/watch?v=7WOR-Yj4fOk&group1=musicvideo - Don't be angry - YouTube&groupno=group43&linkno=link43 the word "Don't be angry" shows on the page as "Don't be angry" however in this link it translates to the ' instead of the apostrophe. I'm not sure why since in the database, it says "Don't" correctly, but it's passing it with that translation. Then, when it gets to the next page (test.php) you get the code I gave above. But it only completes if there is no ' being sent -
Php escape string with GET function issue with apostrophe
PNewCode replied to PNewCode's topic in PHP Coding Help
@Barand I tried that just a few minutes ago too. And sadly no, that just brings me back to the original posts errors The charset I'm using is utf8mb4_unicode_ci now. I just updated the entire table to that from utf8mb3_general_ci -
Php escape string with GET function issue with apostrophe
PNewCode replied to PNewCode's topic in PHP Coding Help
@jodunno Thank you for that. I made those adjustments and I'm still getting an error. I should note that the groupno and linkno don't need to match the db because that is being translated in the url information. It works as long as there is no apostrophe in the values. Uncaught PDOException: SQLSTATE[HY000] [2019] Unknown character set in win1-2.php:17 Stack trace: #0 win1-2.php(17): PDO->__construct() #1 {main} thrown in win1-2.php on line 17 And line 17 is $pdo = new pdo("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=$DB_ENCODING",$DB_USER,$DB_PASS,$options); -
Php escape string with GET function issue with apostrophe
PNewCode replied to PNewCode's topic in PHP Coding Help
Update @mac_gyver I missed changing the character set. So I did that and I get this Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2019] Unknown character set in win1-2.php:18 Stack trace: #0 win1-2.php(18): PDO->__construct() #1 {main} thrown in win1-2.php on line 18 And line 18 is this $pdo = new pdo("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=$DB_ENCODING",$DB_USER,$DB_PASS,$options); and I get this with any test to send without or with an apostrophe -
Php escape string with GET function issue with apostrophe
PNewCode replied to PNewCode's topic in PHP Coding Help
@mac_gyver You are clearly brilliant. So much in fact that I think my brain exploded trying to translate what you said to laymans terms haha. I didn't really understand your instruction, though I tempted to use what you posted with my own connection information and that didn't resolve the issue. Also made it so it doesn't even work without special characters now. I'm feeling certain it's because you explained how to use what you posted and I just don't understand what any of that means. But below is what I tried. Also it returned a new error (below) which doesn't happen when sending a word without an opostrophe Warning: Undefined array key "groupno" in win1-2.php on line 28 Warning: Undefined array key "linkno" in win1-2.php on line 29 <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $DB_HOST = 'removed for posting'; // database host name or ip address $DB_USER = 'removed for posting'; // database username $DB_PASS = 'removed for posting'; // database password $DB_NAME = 'removed for posting'; // database name $DB_ENCODING = 'utf8mb4'; // db character encoding. set to match your database table's character set. note: utf8 is an alias of utf8mb3/utf8mb4 $options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // set the error mode to exceptions. this is the default setting now in php8+ PDO::ATTR_EMULATE_PREPARES => false, // run real prepared queries PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC // set default fetch mode to assoc, so that you don't need to specify it in each fetch statement ]; $pdo = new pdo("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=$DB_ENCODING",$DB_USER,$DB_PASS,$options); $group1 = $_GET['group1']; $link1 = $_GET['link1']; $groupno = $_GET['groupno']; $linkno = $_GET['linkno']; $sql = "UPDATE tourney SET $groupno = '$group1', $linkno='$link1' WHERE id=1"; ?> -
Php escape string with GET function issue with apostrophe
PNewCode posted a topic in PHP Coding Help
Hello. I have a tiny script that sends values to a database, which is grabbed from a different page that has values of the database. On the first page, there are a list of values that are from the db. Next to each line, there is a "send" button This button sends those valuse of that row through a url string to a new page The new page "Gets" those values and inserts them into a different place on the same database table (I don't know why, this doesn't make sense to me but I'm told it has to be this way and I can't change the structure of the db) It all works fine, except times when there's an apostrophe Here's a challenge I've been at for over a week now. I've managed to do this just fine with various escape strings when posting. But since this is GET, all of those methods don't seem to work Does anyone know a working method for this? Also, I can't change each entty manually because these entries could change at any time through the day by various users within a circle of friends. So I would have to watch it 24/7 to correct each one haha. Here is what I have and en example of the string url that gets sent to this is below it NOTE: The groupno and linkno are not a factor here as it works fine and it has a reason of it's own. It works fine when the information has douple quotes or other characters. Just not a single quote or apostrophe <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $servername = "localhost"; $username = "removed for posting"; $password = "removed for posting"; $dbname = "removed for posting"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $group1 = $_GET['group1']; $group1 = str_replace("'", "''", $group1); $link1 = $_GET['link1']; $groupno = $_GET['groupno']; $linkno = $_GET['linkno']; $sql = "UPDATE tourney SET $groupno = '$group1', $linkno='$link1' WHERE id=1"; if (mysqli_query($conn, $sql)) { echo " "; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } mysqli_close($conn); ?> Link Address example https://www.thewebsite/test.php?link1=https://www.youtube.com/watch?v=7WOR-Yj4fOk&group1=musicvideo - Don't be angry - YouTube&groupno=group43&linkno=link43 -
Hello everyone. I hope you're having a great day! I have a series of codes on my page that pic up different things when someone enters a youtube link in a form to send to the database. It works beautifully. I am now to where I need to Add to this to get a duration. The code below successfully gets the title. There is a lot more code on the page but it's not significant to this issue. What I need to do is get the duration and if it's more than 7 minutes long, then a message appears saying that the video is too long, try again. I've been searching for a couple weeks now when I get the time and all I can find is stuff to use with an api key, etc. I don't have that and I really don't want to alter a very long page (over 1000 lines) to adjust to that. So below is my code that gets the title. Is there a way to achieve the time duration limit from this as well? Thank you so very much The example below, if someone enters (aka this link is the $ytvideo1 value) https://www.youtube.com/watch?v=6ROwVrF0Ceg it will output (entered in database function is later in the page not showing below) Chuck Berry - Johnny B. Goode (Live 1958) $linkurl = "$ytvideo1"; parse_str( parse_url( $linkurl, PHP_URL_QUERY ), $vid ); preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:shorts/)?|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $linkurl, $match); $youtube_id = $match[1]; $preurl = "https://www.youtube.com/watch?v=$match[1]"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $preurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $document = htmlspecialchars($output); curl_close($ch); $line = explode("\n", $document); $judul = ""; foreach($line as $strline){ preg_match('/\<title\>(.*?)\<\/title\>/s', $strline, $hasil); if (!isset($hasil[0]) || $hasil[0] == "") continue; $title = str_replace(array("<title>", "</title>"), "", $hasil[0]); }
-
@requinix Indeed! I spent a good part of the day digging in to understand it more, though I'm not totally getting it in my head yet but I understand a lot more now. Luckily, these profiles are on a completely seperate part of the website so the htaccess file only applies to that folder, and there's a different domain name that points to it. So it serves it's purpose. However as you said, if I restructure that then I'll have to revisit how I path the pages. Might end up having to use it by id's only
-
UPDATE: The following works. I'm posting it here in case it helps anyone else. I have to admit though that I don't understand WHY it works and I am going to dig deeper in this so I can understand. I give credit to @requinix because that reply did spark a few flares in this old noggin on some things to search for too Working htaccess code <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) /profile.php?id=$1 [L] </IfModule>
-
UPDATE: I changed the setting in PLESK that I found for the error so that's not an issue anymore. Now it's just a matter of it not working because the page isn't finding the chosen URL value extension
-
@requinix sorry I forgot to mention that. Yes I looked in the logs and the only error is how the htaccess file is affecting other pages with "Option FollowSymLinks not allowed here" but I'll tackle that headache later. I might have to do all of this in a different folder with its own htaccess to avoid all of that (example www.website.com/artist/john...) This is the newest one I have. No errors for it's own page but it's returning my own connection error I made when it can't find the specific name in the database so https://www.examplewebsite.com/profile.php?id=johndoe but https://www.examplewebsite.com/johndoe now just says "Which profile are you trying to see" (from not being able to grab the "custurl" value in the database) (side note: custurl is the row in the database where the value is entered for the chosen friendly url, in this case it being johndoe) ReWriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ profile.php?$1 [L,QSA]